Bash scripting is one of the commonly used scripting by Linux Admins. I have come across a case where I had to change root password of huge count of server's. Direct root login is disabled and authentication is via sudo user. I wrote a very simple "for" loop and it did the task. I want to share that with you and would be helpful for newbies passionate about shell script.
The serverlist contains the list of IP's whose password to be changed. The password was changed to a complex one and not merely PASSWORD. Beware of putting quotes "" and can put wildcards as you wish. The sudouser to be replaced with sudo account.
With SSH, multiple options need to be provided as per the infra requirment. It can range from passing sudo password (Either with sshpass/expect utility) or custom ssh port or disable host key checking..etc depends on how secure your infra is. Here, I provided ssh command line option "-t" as requiretty(Commands execution required a terminal) is mandatory on all serverlist.
But above command was not fully automated. It was prompting for sudo password "[sudo] password for sudouser" and had to provide sudo password manually all the time. It would have been easy if passwordless sudo was configured, but it is not the case most of the times. I break my head to pass sudo password with multiple options and ended in vain. Just provided "sudo -S", but was not working unfortunately.
This script not working..
Any passionate shell scripters, I would really appreciate if any work around which make script fully automated...
Top comments (0)