Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux命令userdel删除用户详解 #11

Open
hehongwei44 opened this issue Oct 13, 2015 · 0 comments
Open

linux命令userdel删除用户详解 #11

hehongwei44 opened this issue Oct 13, 2015 · 0 comments

Comments

@hehongwei44
Copy link
Owner

作用

userdel命令来删除一个用户

用法

userdel [-r] [-f] 用户名

参数介绍

-r: 把用户的主目录一起删除

-f: 强制删除用户,即使该用户已经登录到系统

运用示例

# userdel -r demo

此命令删除用户demo在系统文件中(/etc/passwd, /etc/shadow, /etc/group)的记录,同时删除用户的主目录。

PS: 注意:这里如果用户还在登陆的话,会提示,用户正在登陆无法删除。此时可能需要先强制用户退出。操作步骤如下所示。

强制退出已经登陆用户

查看当前登陆用户的命令:

# w

会输入如下结果:

12:10:27 up 21:13,  1 user,  load average: 0.00, 0.01, 0.08
USER          TTY      FROM                 LOGIN@   IDLE   JCPU   PCPU WHAT
root            pts/0    ***.**.***.**    11:33    0.00s  0.08s  0.00s   w
tmp_3254  ps1       ***.**.***.**     11:33    0.00s  0.08s  0.00s   ls

这里知道了登陆用户的tty是ps1执行强制退出命令pkill:

强制退出

命令原型: pkill -kill -t [TTY]

代码如下:

# pkill -kill -t ps1

执行之后再执行名w 可以看到用户已经退出。

重复执行第二步的删除用户命令,删除成功。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant