Delete a User from an Ubuntu Server in Just 3 Steps

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.

Key Takeaways

  • Logging into a server using an IP address.
  • Listing the users of a server.
  • Deleting a user from a server.

Requirements

  • You need sudo/root privileges to delete a user from a server.
  • A server computer with an IP address.
  • A client computer.

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSflow chart to delete a user from an Ubuntu server

Watch How to Delete a User from an Ubuntu Server

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.

Steps to Follow >

➊ 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.Log into the serverIt 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.

Steps to Follow >

➊ (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.
Command to view current users

List of current userYou 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.Delete a user from Ubuntu serverYou will see something like “Removing user ‘myuser’” and finally “Done”.



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.

Steps to Follow >

❶ Insert the command below on the Ubuntu Terminal:

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.

Showing the user is deletedAs you can see, there is no “myuser” in the “/etc/passwd” file. So, the user “myuser” has been successfully deleted.

❷ Now to exit from the server, execute the following command:

exit
EXPLANATION
  • exit: Quits a shell.
Exiting from the server

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 do I delete a user file in Ubuntu?
You can delete a user file using the option “–remove-home” of the deluser command. If I have a user named “myuser”, the command will go like below

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. The following two commands are required to delete that file and directory:

rm myfile

rm -r mydirectory

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

Related Articles

Rate this post
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment