diff --git a/sources/tech/20190117 How to Update-Change Users Password in Linux Using Different Ways.md b/sources/tech/20190117 How to Update-Change Users Password in Linux Using Different Ways.md deleted file mode 100644 index f2125027c0..0000000000 --- a/sources/tech/20190117 How to Update-Change Users Password in Linux Using Different Ways.md +++ /dev/null @@ -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 -====== - -It’s 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. It’s a native method to set a user password. - -If you don’t 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 it’s, don’t 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 who’s 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 don’t 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 < 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 <