User Account Management: A Developer's Guide to Linux Security
Master user management in Linux to secure your server. Learn to create accounts with useradd, set passwords, and assign groups for better access control.

Previously in this course, we covered Security Auditing Basics to identify potential risks on our system. Now that we know how to spot vulnerabilities, this lesson adds the ability to actively manage our server's security by creating dedicated user accounts and assigning them to appropriate groups.
Effective user management is the cornerstone of server administration. By moving away from the root account and creating specific users for specific tasks, you contain the "blast radius" of any potential mistakes or security breaches.
Creating Users with useradd
On most modern Linux distributions, the useradd command is the low-level utility for account creation. While some distributions offer adduser (a more user-friendly wrapper), useradd is the standard tool you'll encounter on production servers.
To create a new user, you must have root privileges (using sudo). A basic command looks like this:
Bashsudo useradd -m -s /bin/bash developer_user
Breaking down the flags:
-m: This creates the user's home directory (usually/home/developer_user). Without this, the user won't have a personal workspace.-s /bin/bash: This sets the user's default shell to Bash. If you omit this, they might default to a limited shell that makes interactive tasks difficult.
Managing Passwords
Once the account exists, it is locked by default because it has no password. The user cannot log in until you set one using the passwd utility.
Bashsudo passwd developer_user
After running this, the terminal will prompt you to type the new password twice. Note that for security reasons, the characters will not appear on the screen as you type.
Assigning Users to Groups
In Understanding Users and Groups in Linux, we discussed how groups function as the primary mechanism for access control. To grant your new user specific capabilities—like the ability to run administrative commands via sudo—you need to add them to the correct group.
The usermod command allows you to modify an existing account. To add a user to a group, use the -aG (append to group) flags:
Bash# Add the user to the 'sudo' group to grant administrative powers sudo usermod -aG sudo developer_user
Crucial Note: Always use -aG together. If you use -G by itself, you will overwrite the user's existing group memberships, which might lock them out of necessary files.
Hands-on Exercise: Preparing the Web Server
In our ongoing project to harden our web server, we shouldn't run our web application process as root. Let’s create a dedicated service user for the web content.
-
Create the user:
sudo useradd -m -s /usr/sbin/nologin webapp(We use/usr/sbin/nologinfor service accounts to prevent interactive shell logins, which is a security best practice.) -
Verify the user exists:
id webapp -
Assign the user to a group for log access: If you have a log group (often named
admorlog), add the user:sudo usermod -aG adm webapp
Common Pitfalls
- Forgetting the
-mflag: If you create a user without a home directory, they will be dropped into/upon login, which is messy and often forbidden by system policies. - Overusing the root account: Never use the root account for daily tasks. If you find yourself doing everything as root, stop and create a standard user account with
sudoprivileges. - Typo in
usermod -G: As mentioned, missing the-a(append) flag is a common way to accidentally remove a user from their existing groups. Always double-check your command before hitting enter.
FAQ
Q: What is the difference between useradd and adduser?
A: useradd is a binary that interacts directly with system files. adduser is a Perl script (on Debian/Ubuntu) that automates creating the home directory, setting the shell, and prompting for a password in a more interactive way.
Q: How do I delete a user?
A: Use sudo userdel -r username. The -r flag is important—it removes the user's home directory and mail spool, ensuring no orphaned data remains.
Q: How do I see which groups a user is in?
A: Simply run the groups command followed by the username: groups developer_user.
Recap
Managing user accounts is about enforcing the principle of least privilege. By using useradd to create scoped identities, passwd to secure them, and usermod to define their permissions via groups, you create a robust foundation for your server's security.
Up next: We will explore File Archiving and Compression to keep our server's data footprint small and organized.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Custom WordPress Plugin Development
Custom WordPress & WooCommerce plugins built to standard — by the developer behind a plugin with 5,000+ active installs and a SaaS with 10,000+ users.
