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.
CentOS, Debian, or Ubuntu
No Bloatware
SSH and Root Access
Remove a Linux User
- Log into SSH as root.
- 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.” - Kill the user’s processes with one of the following commands:
sudo pkill -KILL -u user1
sudo killall -9 -u user1
- Ensure the user is no longer running any processes. You can use many process managers such as
ps -aux
, top, or htop. - (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.
- Check for cron jobs maintained by the user:
sudo crontab -u user1 -l
- Remove the user’s cron jobs:
sudo crontab -r -u user1
- 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.