Lab environment: CENTOS7 virtual Machines
First create a normal user gubeiqing
.
[[email protected] ~]# useradd gubeiqing[[email protected] ~]# passwd gubeiqingChanging password for user gubeiqing.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully.
This succeeds in creating a normal user and then deleting the user.
[[email protected] ~]# userdel gubeiqing[[email protected] ~]#
The use of the useradd
command was removed, but,,, the problem came when we created gubeiqing
the user again:
[[email protected] ~]# useradd gubeiqinguseradd: warning: the home directory already exists.Not copying any file from skel directory into it.Creating mailbox file: File exists
The file already exists and cannot be created, why is this? Because the user is generated by default when the user is created, 家目录
密码文件
用户组
(without specifying the user group), and 邮箱文件
when the use userdel
of the command is deleted only by deleting the user, and the user's files are still there, then the files need to be completely deleted. I took a look at about four places to deal with.
- Files in the
/home
directory
/etc/passwd
under the user
/etc/group
under the user group
- The
/var/spool/mail
mailbox file under
Delete the files in turn.
1. Delete /home
files from the directory
[[email protected] ~]# cd /home[[email protected] home]# lsgubeiqing[[email protected] home]# rm -rf gubeiqing[[email protected] home]# ls[[email protected] home]#
2. Delete users under /etc/passwd
We can take a look at this file.
[[email protected] ~]# cat/etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/ nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/ sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/ Sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x : 12:100:games:/usr/games:/sbin/nologinftp:x:14:50:ftp user:/var/ftp:/sbin/nologinnobody:x:99:99:nobody:/:/sbin/ NOLOGINSYSTEMD-NETWORK:X:192:192:SYSTEMD Network Management:/:/sbin/nologindbus:x:81:81:system Message Bus:/:/sbin /nologinpolkitd:x:999:997:user for Polkitd:/:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd: X:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologinchrony:x:998:996::/var/lib/chrony:/sbin/ Nologindockerroot:x:997:994:docker user:/var/lib/docker:/sbin/nologingubeiqing:x:1000:1000::/home/gubeiqing:/ Bin/bash
Here you can see all the users in this system, you can see the last line is the user just created, then use the vi
editor to delete the last line of users.
3. Delete /etc/group
the user group file under
Check this file first:
[[email protected] ~]# cat /etc/grouproot:x:0:bin:x:1:daemon:x:2:sys:x:3:adm:x:4:tty:x:5:disk:x:6:lp:x:7:mem:x:8:kmem:x:9:wheel:x:10:cdrom:x:11:mail:x:12:postfixman:x:15:dialout:x:18:floppy:x:19:games:x:20:tape:x:30:video:x:39:ftp:x:50:lock:x:54:audio:x:63:nobody:x:99:users:x:100:utmp:x:22:utempter:x:35:ssh_keys:x:999:input:x:998:systemd-journal:x:190:systemd-network:x:192:dbus:x:81:polkitd:x:997:postdrop:x:90:postfix:x:89:sshd:x:74:chrony:x:996:cgred:x:995:dockerroot:x:994:gubeiqing:x:1000:
Then use vi
the editor to delete the user group.
4. Delete /var/spool/mail
the mailbox file under
[[email protected] ~]# cd /var/spool/mail[[email protected] mail]# lsgubeiqing[[email protected] mail]# rm -rf gubeiqing[[email protected] mail]# ls[[email protected] mail]#
Delete is complete before you create the gubeiqing
user.
[[email protected] mail]# useradd gubeiqing[[email protected] mail]# passwd gubeiqingChanging password for user gubeiqing.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully.
Get!
In addition to this method there is a way to completely delete.
[[email protected] mail]# userdel -rf gubeiqing[[email protected] mail]# useradd gubeiqing[[email protected] mail]# passwd gubeiqingChanging password for user gubeiqing.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully.
Using both methods, users can be completely removed.
Completely remove users under Linux