Adding a New User¶
Introduction¶
Adding users in Linux is a fundamental system administration task.
For security reasons, it is not recommended to work in Linux directly as the root user, as even a minor mistake in a command can lead to irreversible damage to the system or critical files.
A safer and more appropriate approach is to create a separate regular user (for example, vdsuser) and grant them the ability to run administrative commands via sudo. This allows root‑level tasks to be performed only when necessary, maintaining protection against accidental or malicious actions.
Creating a sudo User¶
There are several ways to add a user, but the most common commands are useradd and adduser.
-
Connect to your server via SSH
-
Create a new user
On Ubuntu/Debian, you will then be prompted to set the user’s password immediately. Enter it twice; note that the characters are not displayed as you type.

On CentOS, to set the password you need to run:
Then, on Ubuntu/Debian, provide additional user information (you can leave fields blank).

-
Grant the user sudo privileges by adding them to the sudo group
On Ubuntu/Debian, run:
On CentOS, run:
-
Verify that the user can use sudo
Switch to the new user’s session:
Run a command with sudo privileges (for example, list the
/rootdirectory):If the directory contents appear, the configuration is correct.
Adding a User Using an SSH Key¶
If your server uses an SSH key, password-based login is disabled. To allow a new user to log in successfully, copy your local public key (~/.ssh/authorized_keys) into the new user’s account.
-
Copy the entire
.sshdirectory into the new user’s home -
Set
vdsuseras the owner of that directory usingchown -
After completing the above steps, connect to the server using the SSH key
Note
For Added Security, Disable Remote Access for the Root User
- Open the file
/etc/ssh/sshd_config. - Change the
PermitRootLoginsetting tono. - Press Ctrl‑x, then y, then Enter to save changes and exit the editor.
- Restart the SSH service:
On Ubuntu/Debian:
On CentOS:Useful User Management Commands¶
Basic User Management Commands¶
-
Get user information
-
Change a user’s password
-
Add a user to a group
-
Change a user’s primary group
-
Change a user’s home directory (note: the flag may vary by distribution)
-
View all created users
-
List all users in the system
-
Delete a user
Basic Group Management Commands¶
-
Create a group
-
Delete a group