简体   繁体   中英

How can I change default root password on multi server

How can I change default root password (root's password was provided via CentOS installation) on multi server after I install new CentOS on all those servers.

I can use ansible tool to complete this issue but it's not work with first time root password.

How can I achieve my purpose.

Updated: I don't want login to each server to change password. I want to change root password from remote server via ssh and can complete with at least effort.

Solution:

Use ansible + below command is easiest way to change root pass on multi server.

echo "newpass" | passwd root --stdin

You could try to automate this using Expect. I have used Expect in the past to auto log in to routers to perform actions. Expect scripts are a bit like Macros. You can install Expect with

sudo apt-get install expect

or

yum install expect

You create an expect script and run it for each of your 100 servers (possibly via a shell script). An example basic Expect script just to give you an idea of what it does:

spawn ssh -l admin 123.111.123.11
match_max 100000
expect -ex "This system is for authorized use only.Password:"
send -- "topsecret\r"
expect -ex "Terminal type? \[xterm\]"
send -- "\r"
send -- "\n"
expect -ex "MyServer\[admin\]#"
send -- "/usr/bin/uptime \r\n"
expect -ex "MyServe\[admin\]#"

Obviously you need to change what the script should 'expect' to the actual output from your centos machines as the 'expected' stuff above is for a router. The link below is a more complicated script for setting passwords that might be helpful for you: http://surniaulula.com/2012/10/14/change-passwords-with-ssh-and-expect/

To change your root password after you have completed the installation, use the Root Password Tool. Type the system-config-rootpassword command in a shell prompt to launch the Root Password Tool. If you are not root, it prompts you for the root password to continue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM