添加一个用户并为多台服务器指定相同的密码
我制作了一个脚本,将具有相同密码的同一个用户添加到许多服务器:
#!/bin/bash
password=`cat /root/scripts/password`
for i in `cat /root/scripts/LIST_TEST.txt`
do
printf "Serveur : $i \n"
ssh -tt -o PasswordAuthentication=no $i
adduser newuser
yes `echo $password` | passwd newuser
exit 0
done
此外,使用此脚本时我处于 root 状态,似乎创建了用户,但密码没有更改,因为当我登录时我无法登录尝试 ssh newuser@server
。
令我困扰的是,当我以 root 身份手动登录服务器并执行命令 yes `echo $password` | passwd newuser
然后注销并重试 newuser@server
,它有效...
脚本现在看起来像这样,它更清晰了一些,但它仍然没有添加正确的密码,我不知道它给出的新密码是什么......
#!/bin/bash
password=`cat /root/scripts/password`
for i in `cat /root/scripts/LIST_TEST.txt`
do
printf "Serveur : $i \n"
ssh $i 'adduser newuser; yes $password | passwd newuser'
echo $password
done
I made a script to add one same user with one same password to many servers:
#!/bin/bash
password=`cat /root/scripts/password`
for i in `cat /root/scripts/LIST_TEST.txt`
do
printf "Serveur : $i \n"
ssh -tt -o PasswordAuthentication=no $i
adduser newuser
yes `echo $password` | passwd newuser
exit 0
done
Also I'm in root when using this script, it seems that the user is created but the password doesn't get changed, as I cannot login when I try ssh newuser@server
.
What is bothering me is that when I manually log into the server as root, and do the command yes `echo $password` | passwd newuser
and then logout and try again newuser@server
, it works...
The script looks like this now it is a bit clearer but it still doesn't add the right password, I don't know what it gives as a new password...
#!/bin/bash
password=`cat /root/scripts/password`
for i in `cat /root/scripts/LIST_TEST.txt`
do
printf "Serveur : $i \n"
ssh $i 'adduser newuser; yes $password | passwd newuser'
echo $password
done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试创建一个将更改密码的脚本并在远程计算机中执行该脚本,如下所示:
更改您的第一个脚本:
并且
paschange.sh
将是:请注意,这假设:
'newuser
' 在所有服务器中具有相同的名称Try to create a script which will be changing the passwords and execute that in the remote machine like this:
Change your fist script:
And
paschange.sh
will be:Note that this assumes:
'newuser
' with the same name in ALL servers