I created a new account on my Linux OS, using the useradd command, now I want to delete the account created, I'm trying to use the userdel command to delete that account and I get the following error:

userdel: cannot lock /etc/passwd; try again later.\

I don't understand what that error means.

The syntax I used to delete the account was: userdel -r "accountname" , I also used "accountname" userdel but I didn't work.

Can someone help me delete this account using the command line.

2 Answers 2


Probably because you do not use the userdel command as superuser (root) or other privileged user. Try:

sudo userdel accountname

As stated in several comments it is also possible to remove the homedirectory configured while removing the useraccount using:

sudo userdel -r accountname
  • I just tried sudo userdel accountname and it didn't give me an errors but when I list my home directory the user still appears, If i did rm -r accountname on the home directory would that get rid of the account when I start the machine?
    – Katz
    Nov 9, 2015 at 7:50
  • Useraccounts and homedirectories are seperate things. Use getent passwd accountname (accountname is optional) to lookup accounts and use ls /home to get a list of home directories. If you want to remove a useraccount and to remove the attached homedirectory use sudo userdel -r accountname. If you want to keep the homedirectory, omit the -r flag.
    – Lambert
    Nov 9, 2015 at 7:59
  • Using ls -l /home you can normally see the ownername and groupname on the directories for an existing user. If the homedirectory still exists but the useraccount is removed, you will see numeric value(s) instead, indicating that a user can not be looked up.
    – Lambert
    Nov 9, 2015 at 8:04
  • I was able to get rid of the user account at login with the following command sudo userdel -r accountname but it didn't get rid of the account name on the home directory.
    – Katz
    Nov 9, 2015 at 8:10
  • Also I do see the binary digits when I do ls -l
    – Katz
    Nov 9, 2015 at 8:12

A more modern way to do this is with the deluser command:

  • sudo deluser --remove-all-files $USER_TO_DELETE

See the manual page for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .