Ubuntu

How to Use passwd and adduser to Manage Passwords on Ubuntu 24.04 and Newer

Welcome to the Greenhost.cloud blog! If you’re managing a server or a personal machine running Ubuntu 24.04 or newer, knowing how to effectively manage user accounts and passwords is crucial for maintaining security and usability. In this post, we’ll explore two essential command-line tools: passwd and adduser. These commands allow you to manage user accounts and their associated passwords with ease.

Understanding passwd and adduser

  • passwd: This command is used to change a user’s password. It can be used by users to change their own passwords and by administrators to reset passwords for any user on the system.
  • adduser: This command is employed to create new user accounts. It is a user-friendly front-end to the lower-level useradd command, providing a more intuitive interface for adding new users.

Prerequisites

To perform these tasks, you need to have access to a terminal and appropriate privileges. For most operations, especially adding or modifying user accounts, you will need to have sudo access.

Using adduser to Create New Users

Step 1: Open the Terminal

You can open the terminal in Ubuntu by searching for “Terminal” in the application menu or by using the shortcut Ctrl + Alt + T.

Step 2: Create a New User

To add a new user, type the following command:

sudo adduser username

Replace username with the desired username for the new account.

Step 3: Set User Information

After entering the command, you will be prompted to enter and confirm a password for the new user. You’ll also be asked for additional information such as the user’s full name, room number, work phone, home phone, and other optional details. Press Enter to skip any fields you do not want to fill in.

Step 4: Verify User Creation

Once you complete the prompts, the new user will be created. You can verify the new user by listing all users or checking the /etc/passwd file:

cat /etc/passwd | grep username

Using passwd to Manage Passwords

Step 1: Change Your Own Password

If you want to change your own password, simply type:

passwd

You will be prompted to enter your current password, followed by the new password twice for confirmation.

Step 2: Change Another User’s Password

To change the password for another user, you will need administrative privileges. Use the following command:

sudo passwd username

Replace username with the actual username of the account whose password you wish to change. You will be prompted to enter a new password for that user.

Step 3: Enforcing Password Policies

If you wish to enforce password policies, such as requiring stronger passwords or setting expiration periods, you can modify the /etc/login.defs file or use the chage command to change user password aging settings.

For example, to set the password to expire every 90 days for a specific user, you can use:

sudo chage -M 90 username

Conclusion

Managing user accounts and passwords is a fundamental skill for anyone working with Ubuntu 24.04 and newer. The adduser and passwd commands make it straightforward to add new users and manage their passwords effectively.

By regularly updating passwords and managing user access, you can enhance the security of your system, ensuring that only authorized users have access to sensitive information and resources.

We hope this guide has been helpful for you.