How to Remove a Linux User

You need to know how to remove a Linux user you create on an operating system (OS): CentOS, Debian, Ubuntu, etc. Hopefully, you’re using other user management controls such as least privilege and “need to know” already. Removing unneeded Linux users is an easy way to secure your cloud server from unauthorized access when someone takes a mandatory vacation or is terminated from your organization.

Below we’ll cover how to remove a Linux user on CentOS, Debian, and Ubuntu.

If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.

check markCentOS, Debian, or Ubuntu check markNo Bloatware check markSSH and Root Access

Remove a Linux User

Use htop after you remove a Linux user's processes
  1. Log into SSH as root.
  2. Prevent the user from being able to login and start new processes:
    sudo passwd --lock user1

    You may receive a notification stating “passwd: password expiry information changed.”
  3. Kill the user’s processes with one of the following commands:
    sudo pkill -KILL -u user1

    sudo killall -9 -u user1
  4. Ensure the user is no longer running any processes. You can use many process managers such as
    ps -aux, top, or htop.
  5. (Optional) You may benefit from archiving the user directory before removing it. In other cases, it may be better to simply create a server snapshot or full backup instead. You should also recommend the user to backup their own data from the server and to a PC backup solution for their own safekeeping.
  6. Check for cron jobs maintained by the user:
    sudo crontab -u user1 -l
  7. Remove the user’s cron jobs:
    sudo crontab -r -u user1
  8. Finally, remove the user’s files on the system. The recommended command depends on your Linux distribution.
    CentOS and Arch (remove the CentOS user’s home directory):
    sudo userdel --remove user1
    sudo userdel -r user1

    Remove the user account even if it’s logged in and has processes running:
    sudo userdel -f user1 
    sudo userdel --force user1

    Debian:
    sudo deluser --remove-home user1

Learn more about server management with our Cloud Server Product Guide.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+