linux删除用户账户
How can I remove a Linux user account from Linux system. As you know user management in Linux requires root privileges. While removing user his home directory can be remove or preserved. As same with mail box. User mailbox can be preserved.
如何从Linux系统中删除Linux用户帐户。 如您所知,Linux中的用户管理需要root特权。 在删除用户时,可以删除或保留其主目录。 与邮箱相同。 用户邮箱可以保留。
列出现有帐户 (List Existing Accounts)
Before removing or deleting an user account checking the existing of account can be useful. We can check whether given account exist with different ways. In this example we will use chage
command with -l
list option for user ismail
.
在删除或删除用户帐户之前,请先检查帐户的存在性。 我们可以检查给定的帐户是否以不同的方式存在。 在此示例中,我们将对用户ismail
使用chage
命令和-l
list选项。
$ chage -l ismail
chage: user 'ismail' does not exist in /etc/passwd
chage will give information about specified user
chage将提供有关指定用户的信息
-l test will list users information
-l测试将列出用户信息
- As said before the user is removed so there is no information about the user.如前所述,在删除用户之前,没有关于该用户的信息。
Or we can print the /etc/passwd
in a formatted manner which only list user account names by using cut
command
或者我们可以以格式化的方式打印/etc/passwd
,仅使用cut
命令列出用户帐户名
$ cat /etc/passwd | cut -d ':' -f 1
使用userdel命令删除/删除用户帐户(Remove/Delete User Account with userdel Command)
We can remove given user account with userdel
command like below. In this example we will remove user account named ismail
. As this is an administrative task we need root privileges which can be get with sudo
command.
我们可以使用下面的userdel
命令删除给定的用户帐户。 在此示例中,我们将删除名为ismail
用户帐户。 由于这是一项管理任务,因此我们需要可以使用sudo
命令获得的root特权。
$ sudo userdel ismail
userdel will remove specified test user account
userdel将删除指定的测试用户帐户
删除/删除用户帐户和主目录(Remove/Delete User Account and Home Directory)
The default behavior of the userdel
command is removing user account from user data which resides /etc/passwd
. This will not delete the user account home directory. If we want to remove the user account home directory while removing account with userdel
we should provide the -r
option. In this example we will delete the user account test
and its home directory.
userdel
命令的默认行为是从驻留在/etc/passwd
用户数据中删除用户帐户。 这不会删除用户帐户主目录。 如果要在删除带有userdel
帐户时删除用户帐户的主目录,则应提供-r
选项。 在此示例中,我们将删除用户帐户test
及其主目录。
$ sudo userdel -r test
使用主目录和用户拥有的文件删除/删除用户帐户 (Remove/Delete User Account with Home Directory and User Owned Files)
In previous example we have deleted user account with its home directory. If we want to delete also user owned files and folders while remove user account we can use userdel
command with -f
option. In this example we will remove user account ali
and its home folder and owned files and folders those resides other than his home directory.
在前面的示例中,我们已删除用户帐户及其主目录。 如果要在删除用户帐户的同时删除用户拥有的文件和文件夹,则可以使用带-f
选项的userdel
命令。 在此示例中,我们将删除用户帐户ali
及其主文件夹以及拥有的文件和文件夹,这些文件和文件夹位于其主目录之外。
$ sudo userdel -r -f ali
从passwd文件中删除/删除用户帐户行 (Remove/Delete User Account Line From passwd File)
We have an other less structured option to remove a user account. We can remove the line which user is defined from file /etc/passwd
. As this file contains user details this will remove user account. We can also remove password hash from /etc/shadow
.
我们还有另一个结构较简单的选项来删除用户帐户。 我们可以从文件/etc/passwd
删除用户定义的行。 由于此文件包含用户详细信息,因此将删除用户帐户。 我们还可以从/etc/shadow
删除密码哈希。
如何在Linux中删除删除用户帐户? 信息移植 (How To Delete Remove User Accounts In Linux? Infografic)
翻译自: https://www.poftut.com/delete-remove-user-accounts-linux/
linux删除用户账户