Thanks to nss, there are many ways for a user account to exist. If you have user accounts authenticated with LDAP (say), and use nss tables other than passwd to store user information, then you find that the system automatically creates an entry in the user account database on login. This is handy: it means the user gets listed by lightdm in the greeter, for example, and things like background and keyboard prefs can be known to the greeter. It's all good. However, these users cannot be deleted. If you use the accounts-daemon from the control center to remove them, you get this error: Failed to delete user And alas, the user then stays in the system database. Please make it possible to remove users from the system database even if deluser and userdel don't work on them. How do I drop or remove old users account from my Linux server? I can login using the user’s SSH access, and run ‘sudo -s’ command to become the root user. How can I remove old account, user’s file and directory ownership on Linux? You can remove a Linux user using the userdel command. The userdel delete/remove a user account and related files from the Linux server. Use this command to modify the system account files. It delete all entries that refer to the given user name. Usually, user info removed from the /etc/passwd, /etc/shadow, and /etc/group files.
Advertisement The procedure to remove the user account is as follows:
Let us see all examples and command in details. How to remove a Linux userThe syntax is as follows to remove a user account and related files: userdel -Z user-name-here Where options are as follows for the command:
Warning: Be careful with the userdel command. It delete a user’s home directory/files. Always keep backups. ExamplesDelete a Linux user named jerry:
# ls /home/ To avoid deleting files manually pass the -r to the userdel command. In this example, delete a user named tom: # userdel -r tom # id tom # grep ^tom /etc/{passwd,shadow} # ls /home/ Summing upYou learned how to remove user account from Linux machine. Want to study more? Try to read the following manuals using the man command or help command:
For some reason, I cannot delete users from my server. (see error below) I have tried the following things, with no luck... Anyone have any ideas?
[root@host1 etc]# userdel vscanuser userdel: /etc/passwd.6356: Permission denied userdel: cannot lock /etc/passwd; try again later. Linux 3.10.0-1160.53.1.el7.x86_64 #1 SMP Thu Dec 16 10:19:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
How do I find users in etc passwd? How to examine the /etc/passwd file. The /etc/passwd file contains user information. In recent distributions, “x” is frequently written in the password section of the “/etc/passwd” file. … How do I delete a user from user? It is simple to terminate an account, but you might wish to keep their files and settings in case you need them again. The C:\Users folder contains the account settings and data for each user. How do I completely remove a user in Linux? How do I remove my PSN account from my PS Vita? Using the Secure Shell, log in to your server. Switch to the root user: sudo su – Use the userdel command to remove the old user: username. nYou can also erase that person’s home directory and mail spool by using the -r option with the userdel command.
When I try deleting my user (from a root shell) it says userdel: cannot remove entry 'itaig' from /etc/passwd The user isn't even displayed on /etc/passwd. [root@ab2c1 ~]# su - itaig su: warning: cannot change directory to /home/itaig: No such file or directory -bash-4.1$ exit logout [root@ab2c1 ~]# mkdir /home/itaig [root@ab2c1 ~]# chown itaig.itaig /home/itaig/ [root@ab2c1 ~]# grep itaig /etc/passwd [root@ab2c1 ~]# grep itaig /etc/shadow [root@ab2c1 ~]# userdel -rf itaig userdel: cannot remove entry 'itaig' from /etc/passwd [root@ab2c1 ~]#I have the exact same problem in other servers as well but i can't find a common ground between them: [root@amad ~]# userdel itaig userdel: cannot remove entry 'itaig' from /etc/passwd [root@amad ~]# useradd itaig useradd: user 'itaig' already exists [root@amad ~]#How come my user is not displayed in /etc/passwd but still exists on the system? I've checked /etc/nsswitch.conf and found no problem there... What can be done in order to fix this issue? Edit: The output of strace userdel itaig can be found here: http://pastebin.com/FFkcQ3fj And the output of strace useradd itaig: http://pastebin.com/twRQ7ps0 Second Edit: It seems that if I manually add my user to /etc/shadow and /etc/group I am then able to delete the user using the command userdel itaig , but even then I'm unable to re-create the user as I get an error that the user already exists. Any help would be appreciated! [root@ab2c1 ~]# userdel itaig [root@ab2c1 ~]# useradd itaig useradd: user 'itaig' already exists [root@ab2c1 ~]# userdel itaig userdel: cannot remove entry 'itaig' from /etc/passwd [root@ab2c1 ~]# grep itaig /etc/passwd [root@ab2c1 ~]# grep itaig /etc/group [root@ab2c1 ~]# grep itaig /etc/shadow [root@ab2c1 ~]# id itaig uid=509(itaig) gid=510(itaig) groups=510(itaig) [root@ab2c1 ~]#Contents of /etc/nsswitch.conf: passwd: files nis shadow: files nis group: files nis #hosts: db files nisplus nis dns hosts: files nis dns bootparams: nisplus [NOTFOUND=return] files ethers: files netmasks: files networks: files protocols: files rpc: files services: files netgroup: nisplus publickey: nisplus automount: files nisplus aliases: files nisplusI wonder where the information of the id command comes from: [root@ab2c1 ~]# grep itaig /etc/passwd [root@ab2c1 ~]# grep itaig /etc/shadow [root@ab2c1 ~]# grep itaig /etc/group [root@ab2c1 ~]# id itaig uid=509(itaig) gid=510(itaig) groups=510(itaig) [root@ab2c1 ~]# |