How to Delete a User Account and Home Directory in Ubuntu

The Orphaned Data Problem

When an employee leaves a company, or when a temporary contractor finishes their work on your Ubuntu Linux server, their user account must be deleted immediately for security purposes. However, standard account deletion commands often leave the user’s “home” directory fully intact on the hard drive. If a developer worked on the server for two years, their /home/developer/ directory might contain hundreds of gigabytes of cached files, old docker containers, and abandoned project data. If you simply delete the login credentials, that massive folder becomes orphaned data, permanently consuming your storage space until you manually track it down. To maintain a clean server, you must delete the account and the home directory simultaneously.

Using the userdel Command

The standard Linux userdel (User Delete) command includes a specific flag designed specifically for nuking the user’s home directory alongside their credentials.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. Ensure the user is completely logged out and no running processes belong to them.
  3. To completely delete a user named “john” and wipe his home directory, type the following command:
  4. sudo userdel -r john
  5. Press Enter and provide your administrator password.

Understanding the Output

The -r (Remove) flag is the critical component. The operating system will first delete “john” from the master /etc/passwd and /etc/shadow files, permanently revoking all login access. Next, it will navigate to /home/john/ and recursively delete every single file, folder, and hidden configuration file inside it. Finally, it will delete the /home/john/ folder itself. The terminal will usually return to a blank prompt instantly, indicating the entire operation was successful and the storage space has been recovered.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.