Running all tasks as the root superuser is one of the most dangerous practices in Linux server administration. A single mistyped command can erase your entire filesystem. The industry standard is to create dedicated, unprivileged user accounts and grant them administrative access via sudo.
In this tutorial, you will learn how to create users, organize them into groups, and manage permissions on your RivinCloud VPS.
1. Creating Users with adduser
In Debian and Ubuntu, adduser is the recommended interactive high-level tool that automatically creates a home directory, sets permissions, and prompts for a password.
Add a New User
sudo adduser deployuser
You will be prompted to:
- Enter and confirm a strong password.
- Fill in optional user details (you can press
Enterto skip). - Confirm information by typing
Y.
[!TIP] The low-level utility
useraddrequires manual flags to create home folders (useradd -m -s /bin/bash username).adduseris much safer and easier for beginners.
2. Granting Sudo (Root) Privileges
To allow your new user to run administrative commands using sudo:
sudo usermod -aG sudo deployuser
-a: Append (ensures existing group memberships are not removed).-G: Group specification.
Testing Sudo Access
Switch to the new user and run a test command:
su - deployuser
sudo whoami
(Should output root after prompting for deployuser's password).
3. Managing Groups in Linux
Groups allow you to grant permissions to multiple users simultaneously (such as web developers sharing write access to /var/www/html).
1. Create a New Group
sudo groupadd webdevs
2. Add an Existing User to a Group
sudo usermod -aG webdevs deployuser
3. View Current User's Groups
groups
# Or check another user
groups deployuser
4. Remove a User from a Specific Group
sudo gpasswd -d deployuser webdevs
4. Deleting Users and Groups
When a team member leaves or a service account is deprecated:
Delete User (Keeping Home Directory)
sudo deluser deployuser
Delete User AND Remove Their Home Directory & Mail Spool
sudo deluser --remove-home deployuser
Delete a Group
sudo groupdel webdevs
5. Setting Shared Group Folder Permissions
To allow members of webdevs to collaborate seamlessly in /var/www/html:
# 1. Change group ownership of directory
sudo chown -R root:webdevs /var/www/html
# 2. Grant group write permissions
sudo chmod -R 775 /var/www/html
# 3. Set SGID bit (newly created files automatically inherit group ownership)
sudo chmod -R g+s /var/www/html
Common Mistakes
- Forgetting the
-aflag inusermod -G: Runningusermod -G somegroup userwithout-aremoves the user from all their other supplementary groups (includingsudo). - Leaving default passwords: Always enforce strong password policies or SSH key-only logins.
Troubleshooting
- User cannot run sudo ("user is not in the sudoers file"): Ensure you added them to the
sudogroup (usermod -aG sudo username) and had them log out and back in to refresh group tokens.
Best Practices
- Disable direct root SSH login in
/etc/ssh/sshd_configonce your sudo-enabled user is configured. - Use system service accounts without shell access (
adduser --system --no-create-home) for background daemons.
Frequently Asked Questions
Where are user accounts stored on Linux?
User metadata is stored in /etc/passwd, encrypted password hashes in /etc/shadow, and group definitions in /etc/group.
Conclusion
Proper user and group management is the foundation of Linux system security. Set up dedicated users with sudo privileges today on your RivinCloud VPS!
