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 LTS
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]
- 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.
Steps to Follow >
➊ (Optional) Now, list current users, copy the following command:
cat /etc/passwd | cut -d: -f1
- 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
- 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.
Steps to Follow >
❶ Insert the command below on the Ubuntu Terminal:
cat /etc/passwd | cut -d: -f1
- 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
- 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
Related Articles