Linux User Management 101: adduser, usermod, sudo

Linux User Management 101: adduser, usermod, sudo

Managing users is one of the most fundamental tasks in Linux system administration. Whether you're setting up a personal VPS, multi-user environment, or a game server, understanding how to add, modify, and assign permissions to users is critical.


Why User Management Matters

  • Security: Avoid running everything as root. Use limited user accounts.
  • Access Control: Give users only what they need.
  • Auditing: Know who did what by assigning unique user accounts.
  • Automation: Many services require their own users (e.g. www-data, mysql).

1. Adding a New User with adduser

The adduser command is the simplest way to create a new user interactively.

sudo adduser newusername

You'll be prompted to set a password and fill out optional user info.

This automatically:

  • Creates the user
  • Adds a home directory at /home/newusername
  • Sets up default configuration files (like .bashrc, .profile)

If you're using a minimal OS that doesn't include adduser, use:

sudo useradd -m newusername

Then manually set the password:

sudo passwd newusername

2. Modifying a User with usermod

The usermod command allows you to change properties of an existing user.

Change Username

sudo usermod -l newname oldname

Change Home Directory

sudo usermod -d /new/home/path -m username

Add to Group

Commonly used to give sudo access:

sudo usermod -aG sudo username

Or for Docker:

sudo usermod -aG docker username

Note: Always use -aG to append the group, otherwise it overwrites existing ones.


3. Granting Admin Access with sudo

To allow a user to run commands as root:

sudo usermod -aG sudo username

On some distros, the admin group may be wheel instead:

sudo usermod -aG wheel username

After this, the user can run:

sudo command

To test if sudo works:

su - username
sudo whoami
# Should return 'root'

4. Removing a User

To delete a user (but keep their home directory):

sudo deluser username

To delete user and home directory:

sudo deluser --remove-home username

5. Listing Users and Groups

List all users:

cut -d: -f1 /etc/passwd

See a user's groups:

groups username

Show last login time:

lastlog -u username

Summary

User management on Linux is straightforward but powerful. Use adduser to create users, usermod to adjust their permissions, and sudo to grant admin access safely. Every VPS or server setup benefits from proper access control.

Running a game server, website, or hosting platform? Don’t do it all as root. Set up role-based users, secure your system, and keep control over what each user can access.