翻译完成20190117

This commit is contained in:
MjSeven 2019-02-02 15:34:42 +08:00
parent 50a30b9612
commit dcfc4e5c4e
2 changed files with 251 additions and 251 deletions

View File

@ -1,251 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (MjSeven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Update/Change Users Password in Linux Using Different Ways)
[#]: via: (https://www.2daygeek.com/linux-passwd-chpasswd-command-set-update-change-users-password-in-linux-using-shell-script/)
[#]: author: (Vinoth Kumar https://www.2daygeek.com/author/vinoth/)
How to Update/Change Users Password in Linux Using Different Ways
======
Its a basic thing to set a user password whenever you create an user account in Linux.
Everybody uses passwd command followed by the user name `passwd USERNAME` to set a password for a user.
Make sure you have to set a hard and guess password that will help you to make the system more secure.
I mean to say, it should be the combination of Alphabets, Symbols and numbers.
Also, i advise you to change the password at least once in a month for security reason.
When you use the passwd command it will ask you to enter the password twice to set it. Its a native method to set a user password.
If you dont want to update the password twice and would like to do this in different way?
Yes, we can. There will be a possibility to do.
If you are working as a Linux admin you might have asked the below questions many times.
Some of you may or may not got answer for these questions.
Whatever its, dont worry we are here to answer your all questions.
* How to Update/Change Users Password in Single Command?
* How to Update/Change a Same Password for Multiple users in Linux?
* How to Update/Change Multiple Users Password in Linux?
* How to Update/Change Password for Multiple Users in Linux?
* How to Update/Change Different Password for Multiple Users in Linux?
* How to Update/Change Users Password in Multiple Linux Servers?
* How to Update/Change Multiple Users Password in Multiple Linux Servers?
### Method-1: Using passwd Command
passwd command is a standard method to set or update or change password for users in Linux. The below way is a standard method to do it.
```
# passwd renu
Changing password for user renu.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.
```
Run the following command if you would like to set or change password with single command. This allow users to update password in a single command.
```
# echo "new_password" | passwd --stdin thanu
Changing password for user thanu.
passwd: all authentication tokens updated successfully.
```
### Method-2: Using chpasswd Command
chpasswd is an another command will allow us to set or update or change password for users in Linux. Use the following format if you would like to use chpasswd command to change password for user in a single command.
```
# echo "thanu:new_password" | chpasswd
```
### Method-3: How to Set Different Password for Multiple Users
Use the below script if you would like to set or update or change a password for multiple users in Linux with different password.
To do so, first we need to get a users list by using the following command. The below command will list the users whos having `/home` directory and redirect the output to `user-list.txt` file.
```
# cat /etc/passwd | grep "/home" | cut -d":" -f1 > user-list.txt
```
List out the users using cat command. Remove the user from the list if you dont want to reset the password for the specific user.
```
# cat user-list.txt
centos
magi
daygeek
thanu
renu
```
Create a following small shell script to achieve this.
```
# vi password-update.sh
#!/bin/sh
for user in `more user-list.txt`
do
echo "[email protected]" | passwd --stdin "$user"
chage -d 0 $user
done
```
Set an executable permission to `password-update.sh` file.
```
# chmod +x password-update.sh
```
Finally run the script to achieve this.
```
# ./password-up.sh
magi
Changing password for user magi.
passwd: all authentication tokens updated successfully.
daygeek
Changing password for user daygeek.
passwd: all authentication tokens updated successfully.
thanu
Changing password for user thanu.
passwd: all authentication tokens updated successfully.
renu
Changing password for user renu.
passwd: all authentication tokens updated successfully.
```
### Method-4: How to Set a Same Password for Multiple Users
Use the below script if you would like to set or update or change a same password for multiple users in Linux.
```
# vi password-update.sh
#!/bin/sh
for user in `more user-list.txt`
do
echo "new_password" | passwd --stdin "$user"
chage -d 0 $user
done
```
### Method-5: How to Change User password in Multiple Servers
Use the following script if you want to change a user password in multiple servers. In my case, we are going to change a password for `renu` user. Make sure you have to give the user name which you want to update the password instead of us.
Make sure you have to update the servers list into `server-list.txt` file. Each server should be in separate line.
```
# vi password-update.sh
#!/bin/bash
for server in `cat server-list.txt`
do
ssh [email protected]$server 'passwd --stdin renu <<EOF
new_passwd
new_passwd
EOF';
done
```
You will be getting the output similar to us.
```
# ./password-update.sh
New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: Changing password for user renu.
passwd: all authentication tokens updated successfully.
New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: Changing password for user renu.
passwd: all authentication tokens updated successfully.
```
### Method-6: How to Change User password in Multiple Servers Using pssh Command
pssh is a program for executing ssh in parallel on a number of hosts. It provides features such as sending input to all of the processes, passing a password to ssh, saving output to files, and timing out. Navigate to the following link to know more about **[PSSH Command][1]**.
```
# pssh -i -h /tmp/server-list.txt "printf '%s\n' new_pass new_pass | passwd --stdin root"
```
You will be getting the output similar to us.
```
[1] 07:58:07 [SUCCESS] CentOS.2daygeek.com
Changing password for user root.
passwd: all authentication tokens updated successfully.
Stderr: New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
[2] 07:58:07 [SUCCESS] ArchLinux.2daygeek.com
Changing password for user root.
passwd: all authentication tokens updated successfully.
Stderr: New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
```
### Method-7: How to Change User password in Multiple Servers Using chpasswd Command
Alternatively we can use the chpasswd command to update the password for user in multiple servers.
```
# ./password-update.sh
#!/bin/bash
for server in `cat server-list.txt`
do
ssh [email protected]$server 'echo "magi:new_password" | chpasswd'
done
```
### Method-8: How to Change Multiple Users password in Linux Servers Using chpasswd Command
To do so, first create a file and update username and password in the below format. In my case i have created a file called `user-list.txt`.
See the details below.
Create a following small shell script to achieve this.
```
# vi password-update.sh
#!/bin/bash
for users in `cat user-list.txt`
do
echo $users | chpasswd
done
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/linux-passwd-chpasswd-command-set-update-change-users-password-in-linux-using-shell-script/
作者:[Vinoth Kumar][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/vinoth/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/pssh-parallel-ssh-run-execute-commands-on-multiple-linux-servers/

View File

@ -0,0 +1,251 @@
[#]: collector: (lujun9972)
[#]: translator: (MjSeven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Update/Change Users Password in Linux Using Different Ways)
[#]: via: (https://www.2daygeek.com/linux-passwd-chpasswd-command-set-update-change-users-password-in-linux-using-shell-script/)
[#]: author: (Vinoth Kumar https://www.2daygeek.com/author/vinoth/)
如何使用不同的方式更新或更改 Linux 用户密码
======
在 Linux 中创建用户账号时,设置用户密码是一件基本的事情。
每个人都使用 passwd 命令和用户名,比如 `passwd USERNAME` 来为用户设置密码。
确保你一定设置一个难以猜测的密码,这可以帮助你使系统更安全。
我的意思是,密码应该是字母,符合和数字的组合。
此外,出于安全原因,我建议你至少每月更改一次密码。
当你使用 passwd 命令时,它会要求你输入两次密码来设置。这是一种设置用户密码的原生方法。
如果你不想两次更新密码,并希望以不同的方式进行更新,怎么办呢?
当然,这可以的,有可能做到。
如果你是 Linux 管理员,你可能已经多次问过下面的问题。
你们可能,也可能没有得到这些问题的答案。
无论如何,不要担心,我们会回答你所有的问题。
* 如何用一条命令更新或更改用户密码?
* 如何在 Linux 中为多个用户更新或更改相同的密码?
* 如何在 Linux 中更新或更改多个用户的密码?
* 如何在 Linux 中更新或更改多个用户的密码to 校正:这句和上一句有不同?)
* 如何在 Linux 中更新或更改多个用户的不同密码?
* 如何在多个 Linux 服务器中更新或更改用户的密码?
* 如何在多个 Linux 服务器中更新或更改多个用户的密码?
### 方法-1: 使用 passwd 命令
passwd 命令是在 Linux 中为用户设置,更新或更改密码的标准方法。以下是标准方法。
```
# passwd renu
Changing password for user renu.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.
```
如果希望在一条命令中设置或更改密码,运行以下命令。它允许用户在一条命令中更新密码。
```
# echo "new_password" | passwd --stdin thanu
Changing password for user thanu.
passwd: all authentication tokens updated successfully.
```
### 方法-2: 使用 chpasswd 命令
chpasswd 是另一个命令,允许我们为 Linux 中的用户设置,更新或更改密码。如果希望在一条命令中使用 chpasswd 命令更改用户密码,用以下格式。
```
# echo "thanu:new_password" | chpasswd
```
### 方法-3: 如何为多个用户设置不同的密码
如果你要为 Linux 中的多个用户设置,更新或更改密码,并且使用不同的密码,使用以下脚本。
为此,首先我们需要使用以下命令获取用户列表。下面的命令将列出拥有 `/home` 目录的用户,并将输出重定向到 `user-list.txt` 文件。
```
# cat /etc/passwd | grep "/home" | cut -d":" -f1 > user-list.txt
```
使用 cat 命令列出用户。如果你不想重置特定用户的密码,那么从列表中移除该用户。
```
# cat user-list.txt
centos
magi
daygeek
thanu
renu
```
创建以下小 shell 脚本来实现此目的。
```
# vi password-update.sh
#!/bin/sh
for user in `more user-list.txt`
do
echo "[email protected]" | passwd --stdin "$user"
chage -d 0 $user
done
```
`password-update.sh` 文件设置可执行权限。
```
# chmod +x password-update.sh
```
最后运行脚本来实现这一目标。
```
# ./password-up.sh
magi
Changing password for user magi.
passwd: all authentication tokens updated successfully.
daygeek
Changing password for user daygeek.
passwd: all authentication tokens updated successfully.
thanu
Changing password for user thanu.
passwd: all authentication tokens updated successfully.
renu
Changing password for user renu.
passwd: all authentication tokens updated successfully.
```
### 方法-4: 如何为多个用户设置相同的密码
如果要在 Linux 中为多个用户设置,更新或更改相同的密码,使用以下脚本。
```
# vi password-update.sh
#!/bin/sh
for user in `more user-list.txt`
do
echo "new_password" | passwd --stdin "$user"
chage -d 0 $user
done
```
### 方法-5: 如何在多个服务器中更改用户密码
如果希望更改多个服务器中的用户密码,使用以下脚本。在本例中,我们将更改 `renu` 用户的密码,确保你必须提供你希望更新密码的用户名而不是我们的用户名。
确保你必须将服务器列表保存在 `server-list.txt` 文件中,每个服务器应该在单独一行中。
```
# vi password-update.sh
#!/bin/bash
for server in `cat server-list.txt`
do
ssh [email protected]$server 'passwd --stdin renu <<EOF
new_passwd
new_passwd
EOF';
done
```
你将得到与我们类似的输出。
```
# ./password-update.sh
New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: Changing password for user renu.
passwd: all authentication tokens updated successfully.
New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password: Changing password for user renu.
passwd: all authentication tokens updated successfully.
```
### 方法-6: 如何使用 pssh 命令更改多个服务器中的用户密码
pssh 是一个在多个主机上并行执行 ssh 的程序。它提供了一些特性,例如向所有进程发送输入,向 sshh 传递密码,将输出保存到文件以及超时处理。导航到以下链接以了解关于 **[PSSH 命令][1]**的更多信息。
```
# pssh -i -h /tmp/server-list.txt "printf '%s\n' new_pass new_pass | passwd --stdin root"
```
你将获得与我们类似的输出。
```
[1] 07:58:07 [SUCCESS] CentOS.2daygeek.com
Changing password for user root.
passwd: all authentication tokens updated successfully.
Stderr: New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
[2] 07:58:07 [SUCCESS] ArchLinux.2daygeek.com
Changing password for user root.
passwd: all authentication tokens updated successfully.
Stderr: New password: BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
```
### 方法-7: 如何使用 chpasswd 命令更改多个服务器中的用户密码
或者,我们可以使用 chpasswd 命令更新多个服务器中的用户密码。
```
# ./password-update.sh
#!/bin/bash
for server in `cat server-list.txt`
do
ssh [email protected]$server 'echo "magi:new_password" | chpasswd'
done
```
### 方法-8: 如何使用 chpasswd 命令在 Linux 服务器中更改多个用户的密码
为此,首先创建一个文件,以下面的格式更新用户名和密码。在本例中,我创建了一个名为 `user-list.txt` 的文件。
参考下面的详细信息。
创建下面的小 shell 脚本来实现这一点。
```
# vi password-update.sh
#!/bin/bash
for users in `cat user-list.txt`
do
echo $users | chpasswd
done
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/linux-passwd-chpasswd-command-set-update-change-users-password-in-linux-using-shell-script/
作者:[Vinoth Kumar][a]
选题:[lujun9972][b]
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/vinoth/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/pssh-parallel-ssh-run-execute-commands-on-multiple-linux-servers/