Adding and removing users on Ubuntu servers usually uses command line tools such asadduser
、useradd
、deluser
wait. The following are the detailed steps and instructions:
Add a user
useadduser
Order
adduser
is 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 tosudo
Group to grant superuser permissions:
sudo usermod -aG sudo username
Example:
sudo usermod -aG sudo johndoe
useuseradd
Order
useradd
is 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
usedeluser
Order
deluser
is 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-home
Options:
sudo deluser --remove-home username
Example:
sudo deluser --remove-home johndoe
useuserdel
Order
userdel
is a basic command used to delete users.
Delete users
sudo userdel username
Example:
sudo userdel johndoe
Delete the user and its home directory
use-r
Options can delete the user's home directory and its mail pool:
sudo userdel -r username
Example:
sudo userdel -r johndoe
Summarize
-
Add a user: Recommended
adduser
command, because it is simpler and interactively friendly. -
Delete users:
deluser
Commands 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!