When using a VPS/server, one of the very first things you probably do is creating a new user. In this tutorial you will learn how to create and delete users, create and delete groups, assign a user to a group and more.

Table of Contents

Login as root or use “sudo” with the following commands.

Create a user

adduser <username>
# or
useradd -m <username>
  • This useradd command will create a user with no password, you can assign them a password with:
    passwd <username>
    

Create a group

addgroup <group-name>
# or
groupadd <group-name>

Assign an existing user to an existing group

adduser <username> <group-name>
# or
usermod -aG <group-name> <username>
  • Example: adding user “ricardo” to “sudo” group.
    adduser ricardo sudo
    # or
    useradd -aG sudo ricardo
    
  • In some distros, you may need to install “sudo”, create “sudo” group and modify /etc/sudoers file to grant root permissions to “sudo” group (look for the following line and uncomment it) before adding user to “sudo” group.
    ## Uncomment to allow members of group sudo to execute any command
    %sudo   ALL=(ALL) ALL
    

Delete a user

deluser <username>
# you can add '--remove-home' option to delete home directory or '--remove-all-files' to delete all files owned by user
userdel <username>
# you can add '--remove' to delete home directory

Delete a group

delgroup <group-name>
# or
groupdel <group-name>