When managing a VPS or Dedicated Server, you might want to create a new user and grant them administrative privileges. This can be helpful when you need to give others access to your server without granting them full root access. Here’s a simple guide to achieve this.
Step 1: Log in to Your Server
To get started, log in to your server via SSH as the root user:
Step 2: Create a New User
You can create a new user by running the following command. Replace newuser
with the desired username:
This command creates a new user and sets up the user’s home directory. You’ll also be asked to provide a password for the new user.
Step 3: Add the User to the Sudo Group
To give the new user sudo privileges, you need to add them to the sudo group. On most distributions, users in the sudo
group are granted administrative privileges. Run the following command:
This command adds the new user to the sudo
group, granting them the ability to run commands with elevated privileges.
Step 4: Verify the User’s Access
To verify that the user has sudo privileges, switch to the new user:
Now try running a command with sudo, such as:
You should be prompted for the user’s password. If everything is set up correctly, the user will be able to execute the command.
Step 5: Edit the Sudoers File (Optional)
If you need to configure specific sudo privileges or make advanced modifications, you can directly edit the sudoers file by running:
Make sure to follow the syntax carefully to avoid errors. You can add a line like this to grant full sudo access to the user:
Conclusion
That's it! You've successfully created a new user and added them to the sudoers group on your VPS or Dedicated Server. This user now has the ability to execute administrative commands with sudo
. You can use this method to add multiple users with administrative rights while maintaining control over your server’s security.