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 newusernameYou'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 newusernameThen manually set the password:
sudo passwd newusername2. Modifying a User with usermod
The usermod command allows you to change properties of an existing user.
Change Username
sudo usermod -l newname oldnameChange Home Directory
sudo usermod -d /new/home/path -m usernameAdd to Group
Commonly used to give sudo access:
sudo usermod -aG sudo usernameOr for Docker:
sudo usermod -aG docker usernameNote: 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 usernameOn some distros, the admin group may be wheel instead:
sudo usermod -aG wheel usernameAfter this, the user can run:
sudo commandTo 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 usernameTo delete user and home directory:
sudo deluser --remove-home username5. Listing Users and Groups
List all users:
cut -d: -f1 /etc/passwdSee a user's groups:
groups usernameShow last login time:
lastlog -u usernameSummary
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.