Use of linux userdel Command

  • 2021-08-28 21:43:01
  • OfStack

1. Brief introduction to commands

The userdel (user delete) command is a system administrator command for deleting user accounts and related files.

In fact, the userdel command actually modifies the system's user account files/etc/passwd,/etc/shadow and/etc/group files, which coincides with the idea of "all files for 1 cut operation" in Linux system.

It is worth noting that the userdel command usually does not delete a user account if a process related to the user to be deleted is running. If you do have to delete, you can terminate the user process and then execute the userdel command to delete. But the userdel command also provides a parameter for this case, the-f option.

2. Command format


userdel [options] LOGIN

If no option is added, only the user account will be deleted, but the related files will not be deleted.

3. Description of options


-f, --force
		 Force the deletion of a user, even if the user is currently logged in 
-h, --help
	 Displays help information and pushes 
-r, --remove
	 Delete all files related to the user at the same time as deleting the user, such as deleting the home directory and mail pool 
-R, --root CHROOT_DIR
 	 In  CHROOT_DIR  Apply changes to the directory and use the  CHROOT_DIR  Configuration files in the directory 
-Z, --selinux-user
	 Delete all of the  SELinux  User mapping 

4. Common examples

(1) Delete users, but not their home directories and files.


userdel tom

(2) Delete users, home directory and mail pool.


userdel -r tom

Please don't use the-r option easily. It will delete all files and directories of users at the same time. Remember that if there are important files in the user directory, please back them up before deleting.

(3) Forcibly delete users.


userdel -f tom

The above is the use of linux userdel command details, more information about linux userdel command please pay attention to other related articles on this site!


Related articles: