For instance, if a user no longer needs access to a server, or he has violated some usage policy, or his account has been hacked, the system administrator can decide to delete that user account from the server then. In this article, I will show you how to delete a user from an Ubuntu server.
Process flow chart to delete a user from an Ubuntu server:
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
3 Steps to Delete User in Ubuntu Server
To demonstrate how to delete users in a Ubuntu server, I have used a server and a client computer. I will access the server from the client using an IP address and delete a user named “myuser”.
Step 01: Log into a Server
In the beginning, I will log into the server using the ssh command. Here, the IP address of my server is 172.17.177.87. Now, follow the steps to log into the server:
-
- At first, launch a Ubuntu Terminal on your client computer.
- Now insert the following command to connect to the server:
ssh [email protected]
EXPLANATION- ssh: Uses SSH protocol to connect two computers.
- walid: Name of the User.
- 172.17.177.87: IP address of the Server.
- Provide the password associated with the user.
-
Finally, press the ENTER button from the keyboard.It is showing “Welcome to Ubuntu”. Moreover, the terminal has changed from the previous “walid@Ubuntu” to the new “walid@Server”. So, you are successfully logged into the server.
Step 02: Delete a User from the Server in Ubuntu
In this step, I will delete the user “myuser” from the server. To do so, check the steps:
- (Optional) Now, list current users, copy the following command:
cat /etc/passwd | cut -d: -f1
EXPLANATION- cat: Displays the contents of a file.
- /etc/passwd: Path of the passwd file that contains user information.
- Pipe(|): Redirects the output of one command into another.
- cut: Extracts parts of lines from a file or piped data.
- -d:: Specifies colon (“:”) as a delimiter.
- -f1: Specifies a field. Here number 1 means the first field.
You will see a list of users as shown in the image above. At the bottom, there is a user by the name of “myuser” and I will delete it.
- Now use the following command to delete a user:
sudo deluser --remove-home myuser
EXPLANATION- sudo: Grants root privileges.
- deluser: Deletes user.
- –remove-home: Deletes the home directory of a user.
- myuser: Name of the user that will be deleted.
- Provide the password and hit ENTER.You will see something like “Removing user ‘myuser’” and finally “Done”.
- How to Delete User Account In Ubuntu? [2 Methods]
- Delete User and All Files in Ubuntu [3 Methods]
- Remove User from a Group Using “gpasswd” Command in 3 Steps
Step 03: Verify If the User has been Deleted from Ubuntu Server
Finally, I will verify if the deleting process was successful. This step is optional, so you can skip it if you want. Now, follow the steps to verify whether the user has been deleted from the Ubuntu server:
- Insert the command below on the Ubuntu Terminal:
cat /etc/passwd | cut -d: -f1
As you can see, there is no “myuser” in the “/etc/passwd” file. So, the user myuser has been successfully deleted.EXPLANATION- cat: Displays the contents of a file.
- /etc/passwd: Path of the passwd file that contains user information.
- Pipe(|): Redirects the output of one command into another.
- cut: Extracts parts of lines from a file or piped data.
- -d:: Specifies colon (“:”) as a delimiter.
- -f1: Specifies a field. Here number 1 means the first field.
- Now to exit from the server, execute the following command:
exit
EXPLANATION- exit: Quits a shell.
Conclusion
In this article, I have shown how to delete a user from a Ubuntu server. Hopefully, it was helpful to you.
People Also Ask
How to delete a user from Ubuntu server?
To delete a user named “myuser” from the Ubuntu server, first log into the server and then run the following command:
sudo deluser --remove-home myuser
How to delete in Ubuntu server command line?
To delete something in the Ubuntu server, you need to use the rm
command. For instance, I have a file and a directory by the name of “myfile” and “myfolder” respectively. Now, use rm myfile
command to remove myfile. To remove the directory myfolder, run rm -r myfolder
command.
How do I delete my administrator account?
To delete an administrator account, you need to follow the process of deleting a regular account. Let’s say a system has an administrator account named “admin”. Then you need to follow the command below to delete that account:
sudo deluser admin
How do I add a user to Ubuntu server?
To add a user to the Ubuntu server, first log into the server, then run the following command:
sudo adduser myuser
After running this command, a new user named “myuser” will be added to the Ubuntu server.
Related Articles
- 3 Ways to Delete the User Password in Ubuntu
- How to Delete MySQL User in Ubuntu? [2 Cases]
- Remove A User from Group in Linux [4 Methods]
- How to Delete Multiple Users in Linux? [2 Steps]
FUNDAMENTALS A Complete Guide for Beginners