How to set and change a user password in Linux

The passwd command changes the password for the user and group accounts. Ordinary users can only change the password for their own account, advanced users (or root) can change the password for any account. The administrator of a group can change the password for the group.

The passwd command also changes account information, such as the user's full name, the user's login shell, or the password expiration date and time.

Set user password in Linux

Enter the following passwd command to change your own password:

$ passwd

Sample outputs:

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 or her old password if available. This password is then encrypted and compared with the stored password. The user has only one chance to enter the correct password. Advanced users are allowed to skip this step in order to change the forgotten password. New passwords are checked for complexity. As a general rule of thumb, a password must consist of 10 to 20 characters that include one or more of the following conditions:

  1. Include lower case letters
  2. Include capital letters
  3. Digits 0 to 9
  4. Punctuation / space character

Change the password for another user account in Linux

You need to log in as the root user, enter the following command to change the password for the vivek user :

# passwd vivek

Or:

$ sudo passwd vivek

Sample output:

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

In which, vivek is the username or account name.

Passwords do not appear on the screen when you enter them. For example:

How to set and change a user password in Linux Picture 1

Change the Linux group password

When the -g option is used, the password for the group will be changed. In this example, change the password for the sales group :

# passwd -g sales

The -r option is used with the -g option to remove the current password from the group. This gives the group access to all members. The -R option is used with the -g option to restrict the group to all users.

Change user password on Linux

As a Linux system administrator (sysadmin), you can change the password for any user on your server. To change the password on behalf of the user:

Step 1. First, log in or use 'su' or 'sudo' to access the 'root' account on Linux. Run the command:

sudo -i

Step 2. Then type passwd tom to change the password for the tom user .

The system will prompt you to enter your password twice.

To change or set a new root (superuser) password:

$ sudo passwd

Force Linux users to change their password the next time they log in

By default, Linux passwords never expire for a user. However, you can force the user to change their password the next time you log in via the GUI or CLI method. The syntax is very simple:

$ sudo passwd -e {username} $ sudo passwd --expire {username}

For example:

$ sudo passwd -e marlena

The system will confirm it:

passwd: password expiry information changed.

When a user tries to log in via the ssh command, they should see the following on the screen:

$ ssh marlena@192.168.2.25 Last login: Fri Dec 4 04:12:48 2020 from 192.168.2.105 WARNING: Your password has expired. You must change your password now and login again! Changing password for marlena. Current password: New password: Retype new password: passwd: password updated successfully Connection to 192.168.2.25 closed.

Lock and unlock your account's user password

Note that the following local commands do not disable the account. Users can still log in with another authentication code, such as the SSH key. To disable the account, the administrator should use the command usermod --expiredate 1 {username} or sudo passwd --expire {username} .

Additionally, users with a locked password are not allowed to change their password to comply with the privacy policy set by sysadmin.

You can lock the password as follows:

$ sudo passwd -l {username}

This option disables the password by changing it into a value does not match the value can be encrypted (it adds mark! At the beginning of the password in the file / etc / shadow. To unlock password, to try on:

$ sudo passwd -u {username}

The above command option re-enables the password by changing the password back to the previous value. In other words, return the value before using the -l option .

4 ★ | 2 Vote

May be interested

  • How to change your computer, phone and Mac passwordsHow to change your computer, phone and Mac passwords
    changing a new password (password) on your computer and phone will help you absolutely protect your data and prevent unauthorized people from accessing it when you're not around.
  • How to change VNPT WiFi passwordHow to change VNPT WiFi password
    change vnpt wifi password you need to pay attention to the type of modem you are using, depending on each vnpt modem but how to change the wifi pass vnpt is also different. here are the specific instructions for you guys.
  • What is Unix / Linux?What is Unix / Linux?
    unix operating system is a collection of programs that act as a link between a computer and a user.
  • Instructions for changing Viettel WiFi modem passwordInstructions for changing Viettel WiFi modem password
    the operation of changing viettel wifi password is essential, to be able to secure personal wifi, as well as to ensure the internet connection speed is stable.
  • Change the forgotten password on Windows 8Change the forgotten password on Windows 8
    if you are a user with administrator rights on your computer and unfortunately you forgot your password, your computer will be locked. if that happens, in the usual way you will have to reinstall the system or restore the password using some third-party tools.
  • Change your Facebook password on your phone, how to change mk fbChange your Facebook password on your phone, how to change mk fb
    changing your facebook password on your phone is not the same as changing the pass face on your computer, because the facebook interface on the web and on the mobile app is a bit different. below tipsmake.com will guide you how to change your facebook password on the phone application.
  • How to change the TP-Link wifi password?How to change the TP-Link wifi password?
    in the previous posts, tipsmake.com showed you how to change linksys wifi password and tenda. today, we will share with you how to change the wifi password of tp-link, also a very popular router in vietnam market. please consult.
  • How to change Wifi password, change wifi pass VNPT, FPT, Tenda, TP-Link, Viettel on computer, phoneHow to change Wifi password, change wifi pass VNPT, FPT, Tenda, TP-Link, Viettel on computer, phone
    changing this wifi password will make it easier to change wifi passwords, increase wifi security. here is a summary of how to change wifi pass for the most popular modems, such as: fpt, tenda, tp-link, viettel, please refer.
  • Instructions to change Garena password quickly and easilyInstructions to change Garena password quickly and easily
    instructions on 3 fastest and simplest ways to change garena passwords for gamers, along with tips on how to safely change garena passwords. this will help your account avoid being deleted.
  • Instructions to change Facebook password on computerInstructions to change Facebook password on computer
    to enhance the security layer for facebook accounts, you should choose the password range with unpredictable characters from the moment you create the account. and if you choose the password you are using at a high level of security, you should change your facebook password.