Linux Operation Experimental environment: Centos7 virtual machine First create a common user gubeiqing. [root@localhost ~]# useradd gubeiqing [root@localhost ~]# passwd gubeiqing Changing password for user gubeiqing. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. This successfully creates a normal user, and then deletes the user. [root@localhost ~]# userdel gubeiqing [root@localhost ~]# Use the useradd command to delete it, but... the problem comes. When we create the user gubeiqing again: [root@localhost ~]# useradd gubeiqing useradd: 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? Because when a user is created, the user's home directory, password file, user group (if no user group is specified), and mailbox file are generated by default. When the userdel command is used to delete a user, only the user is deleted, but the user's files are still there, so these files need to be completely deleted. I took a look and found about four areas that needed to be addressed. /home /etc/passwd /etc/group /var/spool/mail Let's delete these files one by one. 1. Delete files in the /home directory [root@localhost ~]# cd /home [root@localhost home]# ls gubeiqing [root@localhost home]# rm -rf gubeiqing [root@localhost home]# ls [root@localhost home]# 2. Delete users under /etc/passwd We can take a look at this file. [root@localhost ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:997:User for polkitd:/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin dockerroot:x:997:994:Docker User:/var/lib/docker:/sbin/nologin gubeiqing:x:1000:1000::/home/gubeiqing:/bin/bash Here you can see all the users in this system. You can see that the last line is the user you just created, so use the vi editor to delete the user in the last line. 3. Delete the user group files under /etc/group Let’s check this file first: [root@localhost ~]# cat /etc/group root: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:postfix man: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 the vi editor to delete this user group. 4. Delete the mailbox files under /var/spool/mail [root@localhost ~]# cd /var/spool/mail [root@localhost mail]# ls gubeiqing [root@localhost mail]# rm -rf gubeiqing [root@localhost mail]# ls [root@localhost mail]# After the deletion is complete, create the gubeiqing user. [root@localhost mail]# useradd gubeiqing [root@localhost mail]# passwd gubeiqing Changing password for user gubeiqing. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. Done! In addition to this method, there is also a method of completely deleting it. [root@localhost mail]# userdel -rf gubeiqing [root@localhost mail]# useradd gubeiqing [root@localhost mail]# passwd gubeiqing Changing password for user gubeiqing. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. Using these two methods, you can completely delete a user. Summarize The above are two methods that I introduced to you to completely delete users under Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: JavaScript to achieve the effect of clicking on the self-made menu
>>: Analysis of MySQL's method of implementing fuzzy string replacement based on regular expressions
At the end of last year, I replaced the opensuse ...
Preface I need to add a synchronized scrolling fe...
Table of contents Preface Option 1: Option 2: Opt...
Table of contents background analyze Data simulat...
Preface In actual development, business requireme...
Additional explanation, foreign keys: Do not use ...
This article describes how to boot the Linux syst...
Table of contents Preface What are enums in TypeS...
The form code is as shown in the figure. The styl...
1. MYSQL installation directory Copy the code as ...
After purchasing an Alibaba Cloud server, you nee...
"Development is more than just writing code&q...
Table of contents 1. Scope 2. Scope Chain 3. Lexi...
It is very convenient to connect to a remote serv...
system: VMTOOLs Download: Link: https://pan.baidu...