SoFunction
Updated on 2025-04-08

How to add and delete users on Ubuntu server

Adding and removing users on Ubuntu servers usually uses command line tools such asadduseruseradddeluserwait. The following are the detailed steps and instructions:

Add a user

useadduserOrder

adduseris a more friendly script for creating new users and setting up related information.

Add new users

sudo adduser username

Example:

sudo adduser johndoe

Set user password

After executing the above command, the system will prompt you to set a password for the new user and fill in some optional user information (such as full name, room number, etc.). These information can be left blank and press Enter to skip.

Add user to a specific group (optional)

If you want new users to have specific permissions, you can add them to the corresponding group. For example, add a user tosudoGroup to grant superuser permissions:

sudo usermod -aG sudo username

Example:

sudo usermod -aG sudo johndoe

useuseraddOrder

useraddis a more basic command that provides more customization options, but is relatively complex to use.

Add new users and create home directory

sudo useradd -m -s /bin/bash username

Example:

sudo useradd -m -s /bin/bash johndoe

Set user password

sudo passwd username

Example:

sudo passwd johndoe

Add user to a specific group (optional)

sudo usermod -aG sudo username

Example:

sudo usermod -aG sudo johndoe

Delete users

usedeluserOrder

deluseris a convenient tool for deleting users and their related files.

Delete users

sudo deluser username

Example:

sudo deluser johndoe

Delete the user and its home directory

If you want to delete the user's home directory and all files at the same time, you can use--remove-homeOptions:

sudo deluser --remove-home username

Example:

sudo deluser --remove-home johndoe

useuserdelOrder

userdelis a basic command used to delete users.

Delete users

sudo userdel username

Example:

sudo userdel johndoe

Delete the user and its home directory

use-rOptions can delete the user's home directory and its mail pool:

sudo userdel -r username

Example:

sudo userdel -r johndoe

Summarize

  • Add a user: Recommendedaddusercommand, because it is simpler and interactively friendly.
  • Delete usersdeluserCommands are more suitable for daily use, especially when you need to delete the user's home directory.

Ensure that you have sufficient permissions when performing these operations (usually requiredsudo) and be careful to avoid accidentally deleting important users or data.

This is the article about how to add and delete users on Ubuntu servers. For more related Ubuntu to add and delete user content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!