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:
$ passwd
Sample Outputs:

Changing password for sisrv
(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:

  1. Lower case alphabetics
  2. Upper case alphabetics
  3. Digits 0 thru 9
  4. 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 sisrv
OR
$ sudo passwd sisrv
Sample putput:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Where,

  • sisrv – is username or account name.

Passwords do not display to the screen when you enter them. For example:

Linux changing user password using passwd

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:

  1. First sign on or “su” or “sudo” to the “root” account on Linux, run: sudo -i
  2. Then type, passwd tom to change a password for tom user
  3. The system will prompt you to enter a password twice

Conclusion

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:

cat /etc/passwd
grep '^userNameHere' /etc/passwd
grep '^tom' /etc/passwd


  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SSH login without password

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login...

How to remove a Linux user

How do I drop or remove old users account from my Linux server? I can login using the user’s SSH...

How to restrict and except SSH access to specific IPs

Once your IP is public it gets attention from so many bots in the internet that do brute force...

How to lock and unlock user account in linux

With the help of two commands you can lock and unlock the user account in Linux. To Lock the...

Adding a user to a group

Synopsis This article describes how to add a Linux user (account) to a group. Environment...

Powered by WHMCompleteSolution