Creating and Managing Users on Your VPS
Setting up multiple users on your VPS can enhance security, streamline access, and enable you to assign specific permissions for different tasks. This guide will walk you through creating and managing users on your VPS using the command line.
Step 1: Access Your VPS via SSH
- Log in via SSH to your VPS with your root or admin credentials.
- Use an SSH client (such as Terminal on macOS/Linux or PuTTY on Windows) and enter the following command:
- Press Enter and provide your root password when prompted.
Step 2: Create a New User
Creating a new user allows you to grant specific access without giving full root privileges.
-
In the SSH terminal, type the following command to create a new user:
Replace
newusername
with the name you’d like for the new user. -
Follow the on-screen instructions to set a password and enter user details (optional). Ensure the password is strong for added security.
Step 3: Grant Root Privileges (Optional)
If the new user needs root or administrative privileges, you can add them to the sudo group.
-
Use the following command to add the new user to the sudoers group:
Replace
newusername
with the actual username you created. -
This grants the new user elevated privileges, allowing them to execute commands as the root user with
sudo
.
Step 4: Set Up SSH Access for the New User
For added security, you may want to set up SSH access specifically for this new user instead of sharing root credentials.
-
Log in as the new user by typing:
-
Create an SSH directory for the new user:
-
Add an SSH Key (if using key-based authentication) by pasting the public key into an authorized keys file:
-
Replace
"your-public-key"
with the actual SSH public key. This setup allows the new user to log in via SSH securely.
Step 5: Manage User Permissions
You can control the actions users can perform by adjusting file permissions and group memberships.
-
View user groups:
This command lists the groups the user belongs to.
-
Add the user to specific groups if necessary. For example, to add a user to a group:
Replace
groupname
with the relevant group name. -
Change file permissions to restrict or allow access to specific files or directories:
Replace
permissions
with the desired permission level andfilepath
with the file or directory path.
Step 6: Delete a User (If Needed)
If a user no longer requires access, you can delete their account to maintain security.
-
Remove the user by typing:
Replace
newusername
with the actual username you wish to delete. -
Delete the user’s home directory and files if you no longer need them:
Step 7: Review and Regularly Update User Permissions
Periodically review user accounts and permissions to ensure only necessary access is provided. This helps maintain the security and integrity of your VPS.