How to add or remove a user on Linux systems

Administration 4 min read

The first task after installing any operating system on your server is to add users who will need to work on this system. And in the future, user management is one of the main tasks of any system administrator, who must also be able to delete an unnecessary account, for example, in the event of an employee’s dismissal.
Understanding the basic steps will help make the process easier and safer. And in this article, we will briefly show you the simple steps to add or remove a user in Linux OS.

 

 

Adding a user

To add a new user to your Linux system, follow these steps:

 

Open a terminal

Access the command line interface by opening a terminal. This is where you will enter commands to manage users.

 

 

Create a new user


Use the "adduser" command. Type it in the command line and press Enter:

 

sudo adduser username


Replace username with the desired name of the new user. You will be asked to set a password and provide additional information, such as your full username.

 

 

Assign the user to groups (optional)


You can assign a new user to specific groups using the usermod command. For example:

 

sudo usermod -aG groupname username

 

Replace groupname with the name of the group you want to add the user to.

 

 


Check that the new user was added correctly


To confirm that the user was added successfully, use the command:

 

id username


Replace username with the actual user name and after executing this command, if the user is successfully created, you will see his identification number in the system.

 

 


Deleting a user

 

When it comes to deleting a user, the process is just as simple. Just use the "deluser" command. Type the following command and press Enter:

 

sudo deluser username

 

Replace username with the name of the user you want to delete.

 


Remove home directory (optional)


To remove a user's home directory along with the user account, add the --remove-home option:

 

sudo deluser --remove-home username

 


Confirm deletion


Verify that the user has been deleted by checking:

 

id username

 

If the user was successfully deleted, you will receive an error message indicating that the user does not exist.

 

 


Conclusion:

Managing users on a Linux system doesn't have to be a difficult task. By following these simple steps, you can easily add or remove users, increasing the security and usability of your system. Remember to exercise caution, especially when deleting users, to avoid unintentional data loss.

2024-01-29 07:24

VISA
MasterCard
Bitcoin
PayPal
Ethereum
Bitcoin Cash
Litecoin
Dogecoin
Tether
Monero
Privat24