How To Add Users In Linux – Adding New User Accounts Guide

If you manage a Linux system, you need to know how to add users in linux for team members or services. This is a basic but essential task for system administration. Adding users correctly ensures proper access control and security.

In this guide, you will learn multiple methods to create user accounts. We cover command-line tools and graphical interfaces. You will also learn how to set passwords, assign groups, and configure home directories.

Why Adding Users In Linux Matters

Every user on a Linux system needs a unique account. This separates files, processes, and permissions. Without proper user management, your system becomes insecure and hard to maintain.

Adding users allows you to:

  • Control who can access the system
  • Track user activity
  • Apply security policies per user
  • Manage file ownership and permissions

Prerequisites For Adding Users

Before you add users, ensure you have:

  • Root or sudo access to the system
  • Basic familiarity with the terminal
  • Understanding of user groups (optional but helpful)

Most Linux distributions come with the necessary tools pre-installed. The useradd and adduser commands are standard.

How To Add Users In Linux

This section covers the primary methods. You can choose the one that fits your workflow.

Method 1: Using The Useradd Command

The useradd command is the low-level tool. It creates a new user but does not set a password or create a home directory by default.

Basic syntax:

sudo useradd username

Example:

sudo useradd john

This creates the user john but no home directory. To create a home directory automatically, use the -m option:

sudo useradd -m john

You can also specify the home directory path:

sudo useradd -m -d /home/john john

To assign a specific user ID (UID):

sudo useradd -u 1005 john

To add the user to one or more groups:

sudo useradd -G sudo,developers john

After creating the user, you must set a password:

sudo passwd john

You will be prompted to enter and confirm the password.

Method 2: Using The Adduser Command

The adduser command is a friendly wrapper around useradd. It is interactive and creates a home directory, sets up default files, and prompts for a password.

Syntax:

sudo adduser username

Example:

sudo adduser jane

You will see prompts for:

  • Password
  • Full name
  • Room number (optional)
  • Work phone (optional)
  • Home phone (optional)
  • Other info (optional)

Press Enter to skip optional fields. The command creates the home directory /home/jane and copies skeleton files from /etc/skel.

This method is simpler for beginners. It handles most defaults automatically.

Method 3: Using A Graphical Interface

If you prefer a GUI, most desktop environments include user management tools. For example, on Ubuntu with GNOME:

  1. Open Settings
  2. Go to Users
  3. Click Unlock to make changes
  4. Click Add User
  5. Enter username, full name, and password
  6. Choose account type (Standard or Administrator)
  7. Click Add

This method is intuitive but less flexible for bulk operations.

Setting User Passwords

Passwords are essential for security. Use the passwd command to set or change a password.

Syntax:

sudo passwd username

You can also force a password change on first login:

sudo passwd -e username

This expires the password immediately. The user must set a new one at next login.

For automated scripts, you can pipe the password:

echo "username:password" | sudo chpasswd

Be careful with plaintext passwords in scripts. Use secure methods in production.

Assigning Users To Groups

Groups simplify permission management. You can add a user to existing groups during or after creation.

Adding User To Groups During Creation

With useradd, use the -G option:

sudo useradd -G sudo,www-data john

With adduser, you cannot specify groups directly. Add them later.

Adding User To Groups After Creation

Use the usermod command:

sudo usermod -aG groupname username

The -a flag appends the user to the group without removing them from other groups. Always use -a with -G to avoid accidental removal.

Example:

sudo usermod -aG docker john

To see which groups a user belongs to:

groups username

Configuring Home Directories

Home directories store user files and configuration. By default, they are created in /home/username.

You can specify a different location:

sudo useradd -m -d /data/users/john john

If you forget to create a home directory, use mkhomedir_helper:

sudo mkhomedir_helper username

Or manually create and set permissions:

sudo mkdir /home/john
sudo chown john:john /home/john
sudo chmod 755 /home/john

The skeleton directory /etc/skel contains default files copied to new home directories. You can customize it.

Setting User Account Expiry

For temporary users, set an expiry date. Use the usermod command with the -e option:

sudo usermod -e 2025-12-31 john

The date format is YYYY-MM-DD. After expiry, the user cannot log in.

To check expiry status:

sudo chage -l john

Creating System Users

System users are for services like web servers or databases. They typically have no login shell and no home directory.

Use the -r flag with useradd:

sudo useradd -r -s /usr/sbin/nologin myservice

System users have UIDs below 1000 (or 500 on some systems). They are not listed in login managers.

Bulk Adding Users

For adding many users at once, use a script or the newusers command.

Using Newusers

Create a file with user details in this format:

username:password:UID:GID:fullname:/home/dir:/bin/bash

Example file users.txt:

alice:pass123:1001:1001:Alice:/home/alice:/bin/bash
bob:pass456:1002:1002:Bob:/home/bob:/bin/bash

Then run:

sudo newusers < users.txt

This creates all users at once. Be careful with password security.

Using A Bash Script

Example script:

#!/bin/bash
for user in alice bob charlie; do
    sudo useradd -m $user
    echo "$user:password123" | sudo chpasswd
done

This loops through a list of usernames. Adjust as needed.

Verifying User Creation

After adding users, verify they exist:

cat /etc/passwd | grep username

Or use id:

id username

Check home directory:

ls -la /home/

Test login (if applicable):

su - username

Common Mistakes And Troubleshooting

Here are typical issues and fixes:

  • User already exists: Use a different username or delete the old one.
  • Home directory not created: Use useradd -m or create manually.
  • Permission denied: Ensure you use sudo.
  • Password not set: Run passwd after creation.
  • User cannot log in: Check shell and home directory permissions.

If you see errors, read the command output carefully. Most issues are self-explanatory.

Deleting Users

To remove a user, use userdel:

sudo userdel username

To remove the home directory and mail spool:

sudo userdel -r username

Be careful: this deletes all user data permanently.

Modifying Existing Users

Use usermod to change user properties:

  • Change username: sudo usermod -l newname oldname
  • Change home directory: sudo usermod -d /new/home username
  • Change UID: sudo usermod -u 1005 username
  • Lock account: sudo usermod -L username
  • Unlock account: sudo usermod -U username

Security Best Practices

When adding users, follow these guidelines:

  • Use strong passwords or SSH keys
  • Assign minimal necessary permissions
  • Remove unused accounts promptly
  • Use groups for access control
  • Enable password expiration policies
  • Disable root login via SSH
  • Regularly audit user accounts

These practices reduce the risk of unauthorized access.

Automating User Management

For large environments, consider automation tools:

  • Ansible: Use the user module
  • Puppet: Use the user resource
  • Chef: Use the user resource
  • LDAP or Active Directory: Centralized user management

Automation ensures consistency across multiple servers.

Frequently Asked Questions

What is the difference between useradd and adduser?

useradd is a low-level command with many options. adduser is a friendly wrapper that guides you through creation. For beginners, adduser is easier.

How do I add a user without a home directory?

Use sudo useradd -M username. The -M flag skips home directory creation.

Can I add a user to multiple groups at once?

Yes, with sudo useradd -G group1,group2 username or sudo usermod -aG group1,group2 username.

How do I add a user with a specific UID?

Use sudo useradd -u 1005 username. Ensure the UID is not already in use.

What happens if I forget to set a password?

The user cannot log in. You must run sudo passwd username to set one.

Conclusion

You now know how to add users in linux using multiple methods. Whether you prefer command-line tools or graphical interfaces, the process is straightforward. Remember to set passwords, assign groups, and configure home directories as needed.

Practice on a test system first. User management is a core skill for any Linux administrator. With these steps, you can efficiently manage user accounts and keep your system secure.