[Translated] userdel Command - Delete User Account from Linux system

This commit is contained in:
geekpi 2014-01-10 02:32:33 +00:00
parent 7dce6e435b
commit 0debabdb70
2 changed files with 62 additions and 64 deletions

View File

@ -1,64 +0,0 @@
Translating---------------geekpi
userdel Command - Delete User Account from Linux system
================================================================================
Maintaining users on the server means add them, modify them and delete them. When a user is no longer need on the system for any reasons, we should delete it to avoid security breach. On Linux system we have **userdel** command to delete a user
![](http://linoxide.com/wp-content/uploads/2013/12/userdel-linux-command.jpg)
### What is userdel ###
Userdel is a low level utility for removing users. On Debian, we should usually use deluser command. Userdel will look the system account files such as **/etc/password** and **/etc/group**. Then it will deleting all entries related to the user name. The user name must exist before we can delete it.
### How to use Userdel ###
Since userdel will modify system account files, we **need root privilege** to run it. Otherwise we will have an error message that saying “*only root can do that*” or similar. After we gain root privilege, we can delete a user by typing userdel from your console. Heres a sample of default usage of userdel
$ sudo userdel pasadena
or
# userdel pasadena
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_default.png)
As you see above, we cant delete a user with name pasadena without root privilege. When we have it, system give us no error which mean that user is deleted successfully.
### Completely remove user home directory ###
Using userdel without options, will only delete the user. User home directory will still remain at /home folder.
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_home_folder.png)
When we go into /home folder, we still seeing pasadena folder which owned by 1002. Created user will usually have a same group name with user name. 1002 was the UID and GID of pasadena user name and pasadena group name.
To completely remove the home user along user deletion, we can use -r option. This option will also delete users mail spool if exist.
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_r.png)
### Force delete a user ###
Userdel provide **-f** option to force user deletion. This option will delete a user even the user still log in into Linux system. Please take a look a sample screenshot.
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_f.png)
Screenshot above show us that pasadena user is logged in to Linux system. It is marked by process **6218** which is SSHD process. But when we do “**userdel -f pasadena**” the command only show us the information that the user is logged in. The command itself was succeed. If we see the content of **/etc/passwd** file using [cat command][1], we dont see pasadena user there. Its home directory still exist but the owner is changed.
One thing that we must know that, userdel with **-f** option **did not broke** the SSH connection. So the user actually still logged in and active even the user is not exist. But when the user log off, the the user can not log in anymore because that user has been deleted.
So **this options is dangerous to use** since it can lead your system into inconsistent state.
Conclusion
Userdel is a tool to delete a user inside Linux system. Userdel also a backend of **deluser command**, a perl script to delete a user. As usual, you can always type **man userdel** to explore more detail about userdel command.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-userdel-command/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/13-cat-command-examples/

View File

@ -0,0 +1,62 @@
userdel 命令 - 从Linux系统中删除用户账户
================================================================================
**userdel** command to delete a user
在服务器上维护用户意味着加入、修改和删除他们。当用户不在需要在系统上时我们需要删除它避免安全缺口。在Linux系统上我们有**userdel**命令来删除一个用户。
![](http://linoxide.com/wp-content/uploads/2013/12/userdel-linux-command.jpg)
### userdel是什么 ###
userdel是一个底层用于删除用户的工具。在Debian上我们应该通常使用deluser命令。userdel会查询系统账户文件例如 **/etc/password** 和 **/etc/group**。那么他会删除所有和用户名相关的条目。在我们删除它之前,用户名必须存在。
### 如何使用userdel ###
既然userdel会修改系统账户文件那么我们**需要root特权**来运行它。不然我们会遇到一个错误信息“*only root can do that*”或者相似的信息。在我们得到特权后我们可以在你的控制台下在userdel后面输入用户名。下面是一个平常默认使用userdel的例子。
$ sudo userdel pasadena
或者
# userdel pasadena
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_default.png)
如你所见我们不能没有root权限而删除用户pasadena。当我们有权限时系统不会给出错误信息这意味着用户已经成功删除。
### 完全删除用户家目录 ###
不带选项使用userdel只会删除用户。用户的家目录将仍会在/home目录下。
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_home_folder.png)
当我们进入/home目录时我们仍旧可以看到1002拥有pasadena文件夹。已创建的用户会有一个与用户名相同的组名。1002是pasadena用户名的UID和GID还是pasadena的组名。
为了在删除用户时完全删除家目录,我们可以使用-r选项。这个选项同样会删除用户的邮件池如果存在的话。
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_r.png)
### 强制删除一个用户 ###
Userdel provide **-f** option to force user deletion. This option will delete a user even the user still log in into Linux system. Please take a look a sample screenshot.
userdel提供了**-f**选项来强制删除用户。这个选项会删除用户及时用户已经登入系统。请看一下示例截图
![](http://linoxide.com/wp-content/uploads/2013/12/userdel_f.png)
截图的上面显示用户pasadena已经登陆了系统。它被标记的进程**6218**是SSHD进程。但是当我们用“**userdel -f pasadena**”只会显示已经登陆的用户的信息。命令本身是成功的。如果我们使用[cat 命令][1]查看**/etc/passwd**的内容我们看不到到用户pasadena存在了。他的家目录还存在但是属主已经改变。
有一点我们必须知道的额是,带**-f**选项的userdel**不会断开**SSH链接。因此用户仍旧是已登录并是活跃的及时用户已不存在。但是当用户登出后用户不再可以登陆因为用户已经删除。
因此**这个选项使用很危险**因为它会使你的系统进入不一致的状态。
总结
userdel是一个Linux系统内部删除用户的工具。userdel同样**deluser**命令的后端一个perl删除用户的脚本。如往常一样你可以输入**man userdel**来探索关于userdel命令的更多细节。
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-userdel-command/
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/13-cat-command-examples/