3 Ways to Delete the User Password in Ubuntu

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

Deleting the user password can remove the hassle of entering a password every time. Moreover, if a user forgets his password and requests to reset the password deleting the existing password is also necessary. In this article, I will show you how to delete the password of a user in Ubuntu.

Process flow chart to delete the user password in Ubuntu:Flow chart for "Delete User Password in Ubuntu"Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS

3 Methods to Delete User Password in Ubuntu

My Ubuntu has a user by the name of “myuser”. In this section, I will show you how to delete the user password of a user who is in this case “myuser” in Ubuntu by using three different methods.

You can read our Comparative Analysis of Methods to distinguish between these three methods and best pick one for your need.

Method 01: Using the passwd Command to Delete User Password in Ubuntu

At first, I will use the passwd command to delete the password of the user “myuser”:

  1. At first, launch a Terminal in Ubuntu.
  2. Write the following command to delete the user’s password:
    sudo passwd -d myuser

    EXPLANATION

    • sudo: Grants root privileges.
    • passwd: Manages Password.
    • -d: Deletes Password.
    • myuser: Name of the user.
  3. Give your password and press ENTER.Delete user password in Ubuntu using the passwd commandIf you see “password expiry information changed” in the output, the password has been deleted successfully.
  4. (Optional) Now, use the following command to switch user:
    su - myuser

    EXPLANATION

    • su: Switch users.
    • : Change the directory to the home directory of the user.
    • myuser: Name of the user.
  5. Switching UserHere you can see, it is not asking for any password.

Method 02: Using the usermod Command to Delete User Password in Ubuntu

Now I will use the usermod command to delete the password of the user “myuser”:

  1. Firstly, open an Ubuntu Terminal.
  2. Copy the following command to delete the password:
    sudo usermod -p '' myuser

    EXPLANATION

    • sudo: Grants root privileges.
    • usermod: Allows to modify user’s login information.
    • -p: Defines new password.
    • : Sets empty password.
    • myuser: Name of the user.
  3. Provide your password and hit ENTER.Delete User Password in Ubuntu using the usermod command
  4. (Optional) Finally, insert the following password to switch user:
    su - myuser

    EXPLANATION

    • su: Switch users.
    • : Change the directory to the home directory of the user.
    • myuser: Name of the user.
  5. Switching UserNow you will be able to switch to the user without a password.



Method 03: Delete User Password from the Shadow File in Linux

In this method, I will delete the user’s password from the shadow file. The shadow file is a text file that contains information about the system’s users’ passwords. To do the same, follow the below steps:

  1. Press CTRL+ALT+T to launch an Ubuntu Terminal.
  2. (Optional) Back up the shadow file by using the following command:
    sudo cp /etc/shadow /etc/shadow.bk
  3. Write the command below to open the shadow file:
    sudo nano /etc/shadow

    EXPLANATION

    • sudo: Grants root privileges.
    • nano: opens a file in the Nano text editor.
    • /etc/shadow: Path of the shadow file.
  4. Find the user and delete the password string.Delete User Password in Ubuntu using the shadow fileHere the password string is between the first two colons (“:”).The shadow file after deleting password stringAfter deleting the password string, the shadow file will look like this.
  5. (Optional) At the end, switch the user using the command below:
    su - myuser

    EXPLANATION

    • su: Switch users.
    • : Change the directory to the home directory of the user.
    • myuser: Name of the user.
  6. Switching user for "delete user password in Ubuntu"You will be able to switch the user without the password.

Comparative Analysis of Methods to Delete User Password in Ubuntu

I have deleted the user password using the passwd command, usermod command and shadow file. Here is a comparison between these three methods.

Methods Pros Cons
Using the passwd command
  • Available in most Linux systems
  • It can be combined with other options to avoid security-related problems.
  • Requires sudo/root privileges.
  • May not work for accounts that use other authentication methods.
Using the usermod command
  • Also allows changing other attributes like home directory and shell.
  • It can also remove the user from supplementary groups.
  • Requires sudo/root privileges.
  • May not work for accounts that use other authentication methods such as SSH authentication.
Using the shadow file
  • Don’t need to use any special command.
  • Can be used if other methods such as usermod or passwd not working.
  • Sudo/root privileges are necessary.
  • Editing shadow isn’t recommended, specially if you are a beginner.

Password Expiry Information Changed in Linux

Setting a password expiry date helps to improve the security of user accounts. It also encourages users to change their password regularly. To set the password expiry date, follow the steps shown below:

  1. At first, launch a Ubuntu Terminal.
  2. Insert the following command to view the current expiry date:
    sudo chage -l myuser

    EXPLANATION

    • sudo: Grants root privileges.
    • chage: Is used to view and change user password expiry information.
    • -l: Shows expiry information.
    • myuser: Name of the user.
  3. Printing current expiry dateHere, it is showing the “password expires” at “never” and the “maximum number of days between password change” is “99999”. Now I will give a specific expiry date.

  4. Now type the following command to change the expiry date:
    sudo chage -M 120 myuser

    EXPLANATION

    • sudo: Grants root privileges.
    • chage: Is used to view and change user password expiry information.
    • -M: Specifies the maximum number of days that the password remains valid.
    • 120: Maximum number of days.
    • myuser: Name of the user.
  5. Changing expiry date

  6. Finally, view the new expiry date using the following command:
    sudo chage -l myuser

    EXPLANATION

    • sudo: Grants root privileges.
    • chage: Is used to view and change user password expiry information.
    • -l: Shows expiry information.
    • myuser: Name of the user.
  7. Changed expiry dateAs you can see, it is showing password expires on “Aug 05, 2023” and “the maximum number of days between password change” is “120”.



How to Change User Password in Linux

Changing passwords on regular basis is necessary. It protects the accounts from unauthorized access. Here I have shown simple ways to change a user password:

  1. Hold CTRL+ALT+T to open a Terminal in Ubuntu.
  2. Copy the following to switch user:
    su - myuser

    EXPLANATION

    • su: Switch users.
    • : Change the directory to the home directory of the user.
    • myuser: Name of the user.
  3. Switching user

  4. Now use the following command to change the user’s password:
    passwd

    EXPLANATION

    • passwd: Changes and manages user passwords.
  5. Give the current password and press ENTER.
  6. Type a new password and hit ENTER.
  7. Finally, retype the password and press ENTER to complete the process.Changing password using the passwd command You should see a message saying “password updated successfully”.

Conclusion

In this article, I have shown you how to delete a user password in Ubuntu in 3 different ways with comparative analysis, so that choose which one suits you better. In addition, I have provided some complementary information. Moreover, you should check out the questions below which might be helpful for you.

People Also Ask

Can I change the user password in Ubuntu?

Absolutely. To change the user password in Ubuntu, use the passwd command followed by the user name and prefix with sudo. For example, to change the password for the user walid, open the terminal and type the command sudo passwd walid, input the new password and confirm prompted.

How to delete user Ubuntu?

 The best way to delete users in Ubuntu is using the deluser command. For instance, if you have a user by the name of “creed”, you can use the command sudo deluser –remove-home creed to delete the user with his home directory.

How to switch user in Ubuntu?

To switch users in Ubuntu, open the terminal and type the command su <other_user>. Upon hitting the ENTER button, enter the other_user password when prompted to successfully switch users in Ubuntu.

How to delete user with ID in Ubuntu?

To delete a user with his user ID, you can use the deluser command. For example, if a user’s ID is 1005 then you can use the following command to delete that user

sudo deluser -u 1005

How to delete user profile?

To delete user profile, run the command: sudo deluser –remove-home USERNAME. It will delete the user account with its home directory.

How do I Delete a user without admin rights?

To delete a user, you need to have admin rights. You can ask the system administrator to grant you sudo privileges. Only then you will be able to delete a user.

Related Articles

5/5 - (1 vote)
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

1 thought on “3 Ways to Delete the User Password in Ubuntu”

Leave a Comment