Skip to content

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.

  1. Connect to your server via SSH

    ssh root@ip_address
    
  2. Create a new user

    adduser vdsuser
    

    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:

    passwd vdsuser
    

    Then, on Ubuntu/Debian, provide additional user information (you can leave fields blank).

  3. Grant the user sudo privileges by adding them to the sudo group

    On Ubuntu/Debian, run:

    usermod -aG sudo vdsuser
    

    On CentOS, run:

    usermod -aG wheel vdsuser
    
  4. Verify that the user can use sudo

    Switch to the new user’s session:

    su - vdsuser
    

    Run a command with sudo privileges (for example, list the /root directory):

    sudo ls -la /root
    

    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.

  1. Copy the entire .ssh directory into the new user’s home

    cp -r ~/.ssh /home/vdsuser
    
  2. Set vdsuser as the owner of that directory using chown

    chown -R username:vdsuser /home/vdsuser/.ssh
    
  3. After completing the above steps, connect to the server using the SSH key

    ssh <vdsuser>@<ip_address>
    

Note

For Added Security, Disable Remote Access for the Root User

  • Open the file /etc/ssh/sshd_config.
  • Change the PermitRootLogin setting to no.
  • Press Ctrl‑x, then y, then Enter to save changes and exit the editor.
  • Restart the SSH service:

On Ubuntu/Debian:

sudo service ssh restart
On CentOS:

sudo service sshd restart

Useful User Management Commands

Basic User Management Commands

  • Get user information

    id username
    

  • Change a user’s password

    passwd username
    

  • Add a user to a group

    usermod -G group_name username
    

  • Change a user’s primary group

    usermod -g group_name username
    

  • Change a user’s home directory (note: the flag may vary by distribution)

    usermod -g group_name username
    

  • View all created users

    cat /etc/passwd
    

  • List all users in the system

    w
    

  • Delete a user

    deluser username
    

Basic Group Management Commands

  • Create a group

    groupadd group_name
    

  • Delete a group

    delgroup group_name
    

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×