Adding users

For day-to-day administration of a Linux server, it is not recommended to run as the root superuser. Entering the wrong command can cause irreversible system crash and file corruption. Therefore, it is desirable to create a VPS server user with sudo privileges.

Create a user with sudo privileges

1. Create a user and give him the rights to perform actions on behalf of the super administrator root:

useradd -G sudo -s /bin/bash -m sudo_user

sudo_user – example of a new username with sudo privileges.

2. Set a password for the sudo_user user:

passwd sudo_user

3. To check, try connecting to the server as the created user sudo_user

Linux/MacOS: execute in terminal:

ssh sudo_user@IP.server.address

Windows: connect to the server via PuTTY. In the login as field, enter sudo_user.

After connecting to the server, change the user to root:

sudo su

If the new sudo_user is working properly, the name should change to root.

Run the exit command to end the session as root. The username will be changed to sudo_user.

In order to disable remote access of the root user, you need to modify the /etc/ssh/sshd_config file. Open the file:

sudo nano /etc/ssh/sshd_config

4.    Find the line PermitRootLogin in this file. Enter in the field value:

PermitRootLogin no

Restart SSH:

  sudo service ssh restart

Working with users

When a user is created, he will be added to the group by default with the name corresponding to his name. You can also use the –G switch to specify additional groups for the user being created.

For example, this command will add the user to the sudo_user group and to the sudo_group.

Accordingly, in the next command, the username will be added to the username group, as well as to the sudo group, since the -G switch allows you to specify additional groups for the user:

useradd -G sudo_group -s /bin/bash -m sudo_user

If you want to add a user to a new group, first you need to create this group:

addgroup group_name

Then create a user:

useradd -g group_name sudo_user

To add an existing user to the group, use the usermod command:

usermod -G group_name sudo_user

To change the primary group of a user:

usermod -g group_name sudo_user 

To get information about a user:

id sudo_user 

To delete a user:

deluser sudo_user 

To remove a group:

delgroup group_name

If you have any questions, please create a ticket to technical support.