Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to completely delete a user in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How do I completely delete a user in Linux? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

First create a normal user gubeiqing.

[root@localhost ~] # useradd gubeiqing [root@localhost ~] # passwd gubeiqingChanging password for user gubeiqing.New password:BAD PASSWORD: The password is a palindromeRetype 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 ~] #

It was deleted using the useradd command, but here's the problem when we create the user gubeiqing again:

[root@localhost ~] # 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? Because the user's home directory, password file, user group (without specifying a user group), and mailbox files are generated by default when creating a user, and when deleting using the userdel command, only the user is deleted, and the user's file is still there, so these files need to be deleted completely. I took a look. There are about four areas that need to be dealt with.

/ home/etc/passwd/etc/group/var/spool/mail

Delete these files in turn.

1. Delete files in the / home directory

[root@localhost ~] # cd / home [root@localhost home] # lsgubeiqing [root@localhost home] # rm-rf gubeiqing [root@localhost home] # ls [root@localhost home] #

two。 Delete users under / etc/passwd

We can take a look at this file.

[root@localhost ~] # 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, and you can see that the last line is the user you just created, so use the vi editor to delete the user on the last line.

3. Delete the user group file under / etc/group

Take a look at this file first:

[root@localhost ~] # 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 delete the user group using the vi editor.

4. Delete mailbox files under / var/spool/mail

[root@localhost ~] # cd / var/spool/mail [root@localhost mail] # lsgubeiqing [root@localhost mail] # rm-rf gubeiqing [root@localhost mail] # ls [root@localhost mail] #

Delete is complete, and then create the gubeiqing user.

[root@localhost mail] # useradd gubeiqing [root@localhost mail] # passwd gubeiqingChanging password for user gubeiqing.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully.

Got it!

In addition to this method, there is another way to delete it completely.

[root@localhost mail] # userdel-rf gubeiqing [root@localhost mail] # useradd gubeiqing [root@localhost mail] # passwd gubeiqingChanging password for user gubeiqing.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully. What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report