Managing users is an essential part of administering a Linux VPS. This guide explains how to create, delete, and manage user accounts on your server, including setting passwords, granting sudo access, and managing permissions.
1. Create a New User
To create a new user, log in to your VPS via SSH and run:
adduser username
Replace username with the desired name for the new user.
You’ll be asked to set a password and provide optional user information (you can press Enter to skip those).
2. Set or Change a User’s Password
To set or update a password for any user:
passwd username
You’ll be prompted to enter and confirm the new password.
3. Grant Sudo (Admin) Access
To allow a user to perform administrative tasks with sudo:
usermod -aG sudo username
This adds the user to the sudo group, which grants permission to run commands as root using sudo.
Example usage:
sudo apt update
4. View Existing Users
You can list all users by viewing the /etc/passwd file:
cat /etc/passwd
Each line corresponds to a user account.
To see currently logged-in users:
who
5. Switch Between Users
To switch to another user account:
su - username
To return to your previous user session, type:
exit
6. Delete a User
To remove a user:
deluser username
To delete the user and their home directory:
deluser --remove-home username
Be careful with this command, especially when removing system users or important accounts.
7. Lock or Unlock a User Account
To lock a user account (disables login):
usermod -L username
To unlock it:
usermod -U username
8. Disable Shell Access (Optional)
To prevent a user from logging in via SSH but still allow file access (e.g., for SFTP-only users):
usermod -s /usr/sbin/nologin username
Conclusion
User management is a key skill for any VPS administrator. By creating limited-access user accounts and assigning sudoprivileges as needed, you can better secure and organize your server.
If you need help managing users or recovering access to your VPS, feel free to contact Hosteons Support.