添加一个用户并为多台服务器指定相同的密码

发布于 2025-01-09 09:32:39 字数 932 浏览 1 评论 0原文

我制作了一个脚本,将具有相同密码的同一个用户添加到许多服务器:

#!/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[旋木] 2025-01-16 09:32:39

尝试创建一个将更改密码的脚本并在远程计算机中执行该脚本,如下所示:

更改您的第一个脚本:

#!/bin/bash
password=`cat /root/scripts/password`
for i in `cat /root/scripts/LIST_TEST.txt`
do
        printf "Serveur : $i \n"
        #Password is passed as $1 to the next script
        cat ./paschange.sh $passwd | ssh $i #Command to excecute the  script
        echo $password
done

并且 paschange.sh 将是:

#!/bin/bash
adduser newuser
yes $1 | passwd newuser #Password is passed as $1

请注意,这假设:

  1. 您将创建一个用户命名:'newuser' 在所有服务器中具有相同的名称
  2. 他将在所有服务器上使用相同的密码
  3. 您正在使用相同的名称登录到所有这些服务器来运行脚本,这是您的用户名您当前正在执行此脚本的计算机上有。

Try to create a script which will be changing the passwords and execute that in the remote machine like this:

Change your fist script:

#!/bin/bash
password=`cat /root/scripts/password`
for i in `cat /root/scripts/LIST_TEST.txt`
do
        printf "Serveur : $i \n"
        #Password is passed as $1 to the next script
        cat ./paschange.sh $passwd | ssh $i #Command to excecute the  script
        echo $password
done

And paschange.sh will be:

#!/bin/bash
adduser newuser
yes $1 | passwd newuser #Password is passed as $1

Note that this assumes:

  1. You will create a user named: 'newuser' with the same name in ALL servers
  2. He will have the same password for all servers
  3. You are using the same name to login yourself to all those servers to run the script, which the username you have on the computer you are currently executing this script.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文