Ubuntu – How to remove a user completely from Ubuntu 16.04

16.04active-directoryunityusers

I have set up Ubuntu 16.04 with PowerBroker Identity Services to login with users from an Active Directory database.

Whenever I login with a new account, the user is added to the list of users that appear when clicking the gears in the top right corner of the unity panel. The Lock/Switch Account list.

Often I need to test what happens the first time a user logs in, but what is the correct way to 'reset' a user that has been logged on to the system?

I can delete their home directories etc., PowerBroker has a cache that I clear as well, but the accounts still appear in the top right corner, so they're evidently not completely removed.

I have been looking into the FreeDesktop Accounts Service, thinking that might include some functionality to 'clean up' a user account, but I haven't found anything that seems related to that.

Things I have tried include, but are not limited to:

sudo userdel [username] 
sudo rm -rf [home]
sudo rm /var/log/btmp
sudo rm /var/log/wtmp
sudo rm -rf /var/cache/lightdm/dmrc

userdel returns:

userdel: cannot remove entry '[username]' from /etc/passwd  
/usr/sbin/deluser: `/usr/sbin/userdel [username]' returned error code 1. Exiting.

The user does not exist in /etc/passwd (they exist only in Active Directory).

[username] is the username of the user as read from $USER with \s being escaped and [home] is the path as read from $HOME.

Best Answer

use the command from terminal

sudo userdel <username>

after this you can delete the home directory of that user using

rm -r -f </home/username>
Related Question