Linux Set or Change User Password
How do I set or change Linux system password for any user account? How can I change user password on Linux operating system using the command-line options?
Both Linux and UNIX-like operating systems use the passwd command to change user password. The passwd is used to update a user’s authentication token (password) stored in /etc/shadow file. The passwd change passwords for user and group accounts. A normal user may only change the password for his/her own account, the super user (or root) may change the password for any account. The administrator of a group may change the password for the group. passwd also changes account information, such as the full name of the user, user login shell, or password expiry date and interval.
Linux Set User Password
Type following passwd command to change your own password:
Changing password for vivek (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
The user is first prompted for his/her old password if one is present. This password is then encrypted and compared against the stored password. The user has only one chance to enter the correct password. The super user is permitted to bypass this step so that forgotten passwords may be changed. A new password is tested for complexity. As a general guideline, passwords should consist of 10 to 20 characters including one or more from each of following sets:
- Lower case alphabetics
- Upper case alphabetics
- Digits 0 thru 9
- Punctuation marks/spacial characters
Linux change password for other user account
You need to login as the root user, type the following command to change password for user vivek:
# passwd vivek
$ sudo passwd vivek
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
- vivek – is username or account name.
Passwords do not display to the screen when you enter them. For example:
Linux Change Group Password
When the -g option is used, the password for the named group is changed. In this example, change password for group sales:
# passwd -g sales
The current group password is not prompted for. The -r option is used with the -g option to remove the current password from the named group. This allows group access to all members. The -R option is used with the -g option to restrict the named group for all users.
Changing user passwords on Linux
As a Linux system administrator (sysadmin) you can change password for any users on your server. To change a password on behalf of a user:
- First sign on or “su” or “sudo” to the “root” account on Linux, run: sudo -i
- Then type, passwd tom to change a password for tom user
- The system will prompt you to enter a password twice
The passwd command line utility is used to update or change user’s password. The encrypted password is stored in /etc/shadow file and account information is in /etc/passwd file. To see all user account try grep command or cat command as follows:
grep '^userNameHere' /etc/passwd
grep '^tom' /etc/passwd