linux shell sshpass remote server batch change password

The command is as follows:

# 作用:把192.168.101.91服务器原密码:111111改成Softsec@2020CN
sshpass -p "111111" ssh -o StrictHostKeyChecking=no [email protected] "echo 'Softsec@2020CN' |passwd --stdin root"

Command explanation:

The first part: sshpass -p "111111" ssh -o StrictHostKeyChecking=no [email protected]

The root user of the server 192.168.101.91 is remotely connected through the sshpass plug-in. The principle of sshpass is similar to the expect plug-in, that is, it simulates manual input of the password.

But there is a problem with sshpass. When the terminal connects to a server for the first time, there will be a prompt "Are you sure you want to continue connecting (yes/no)?", so it can't connect, but add " -o StrictHostKeyChecking =no "parameter, you can solve this problem.

Part 2: echo'Softsec@2020CN' |passwd --stdin root

@This command means: modify the root user password, and enter the new password to fill in the previous content "Softsec@2020CN" by default.

In this way, you can successfully modify any server password with one command. If you use it for one time, it is easier to copy 200 of these commands directly, and then batch modify the parameters of the command and put it into the shell script to run it.

sshpass detailed reference:

"Linux non-interactive ssh sshpass introduction" https://blog.csdn.net/whatday/article/details/103008743

"Introduction to linux sshpass non-interactive ssh password verification" https://blog.csdn.net/whatday/article/details/108923248

 

 

Guess you like

Origin blog.csdn.net/whatday/article/details/113921464