Prerequisites:
- Linux server with root/sudo access
- SSH or console access to your server
Why Create a Personal User?
Security
Disabling root login prevents attackers from directly accessing the root account, even if they obtain credentials.
Accountability
Using personal accounts makes it easier to track who performed what actions on the system.
Best Practice
Industry standard security practice recommended by security experts and compliance frameworks.
Flexibility
Multiple users can have sudo access, allowing for better access management.
Creating a Personal User
1
Create a new user
Create a new user account (replace You’ll be prompted to:
username with your desired username):- Set a password (choose a strong password)
- Provide optional user information (full name, room number, work phone, etc.)
- Confirm the information
You can also use
useradd instead of adduser, but adduser is more interactive and user-friendly on Debian/Ubuntu systems.2
Add user to sudo group
Grant sudo privileges to the new user:This adds the user to the
sudo group, which allows them to execute commands with administrative privileges.On some systems (like RHEL/CentOS), the group might be called
wheel instead of sudo. Use: sudo usermod -aG wheel username3
Verify user creation
Switch to the new user and verify sudo access:If successful,
sudo whoami should return root. This confirms that:- The user account was created successfully
- The user has sudo privileges
- You can execute administrative commands
4
Test sudo access
Try running a command that requires sudo:You’ll be prompted for your user’s password (not root’s password). If the command executes successfully, your sudo access is working correctly.
Alternative: Create User with Sudo in One Command
You can create a user and add them to the sudo group in a single command:useradd:
Managing User Accounts
Change user password
Change user password
Change a user’s password:You’ll be prompted to enter the new password twice.
Remove sudo privileges
Remove sudo privileges
Remove a user from the sudo group:
Add user to additional groups
Add user to additional groups
Add a user to additional groups:Common groups:
sudoorwheel- Administrative privilegesdocker- Docker accesswww-data- Web server access
Delete a user account
Delete a user account
Delete a user account:
List all users
List all users
View all users on the system:
View user information
View user information
Get detailed information about a user:
Sudo Configuration
Understanding Sudo
Sudo (Super User Do) allows users to run commands with the privileges of another user, typically root. Users in thesudo group can execute administrative commands by prefixing them with sudo.
Sudo Configuration File
The sudo configuration is located at/etc/sudoers. Never edit this file directly! Always use visudo:
Common Sudo Configurations
Allow sudo without password
Allow sudo without password
Allow specific users to use sudo without entering a password:Add this line (replace
username):Restrict sudo to specific commands
Restrict sudo to specific commands
Allow a user to run only specific commands with sudo:This allows the user to only run
apt and systemctl with sudo.Sudo timeout
Sudo timeout
By default, sudo remembers your password for 15 minutes. To change this:Set to
0 to require password every time, or a number for minutes.Security Best Practices
Strong Passwords
Use strong, unique passwords for all user accounts. Consider using a password manager.
Limit Sudo Access
Only grant sudo access to users who need it. Regularly review who has sudo privileges.
Regular Audits
Periodically review user accounts and remove unused or unnecessary accounts.
SSH Keys
After creating your user, set up SSH key authentication instead of passwords. See our SSH Security guide.
Next Steps
After creating your personal user account:- Set up SSH keys - Configure key-based authentication for your new user. See SSH Security.
- Disable root login - Once you’ve verified your user account works, disable root SSH access.
- Configure firewall - Set up UFW to protect your server. See Firewall Configuration.
Troubleshooting
User can't use sudo
User can't use sudo
Verify the user is in the sudo group:If not, add them:The user may need to log out and back in for changes to take effect.
Permission denied errors
Permission denied errors
Check:
- User is in sudo group:
groups username - Sudoers file syntax:
sudo visudo -c - User is using
sudoprefix:sudo command
Can't switch to new user
Can't switch to new user
If
su - username fails:- Verify user exists:
id username - Check if account is locked:
sudo passwd -S username - Ensure user has a valid shell:
cat /etc/passwd | grep username
Remember: Always test your user account thoroughly before disabling root login. Keep a root session open as a backup until you’re confident everything works.
