Hello! 欢迎来到小浪云!


Linux执行usermod时提示user xxx is currently logged in


avatar
小浪云 2024-07-14 45


近日遇到一怪事,执行usermod更改用户家目录时,被提示usermod: user xxx is currently logged in,可是用户根本没有登陆到系统里啊。查了下,网上普遍的解决方法是备份以后清空/var/run/utmp文件,再重启以后就好了。可说的容易,服务器哪是想重启就重启的?

$ usermod -d /some/opther/path userfoo

usermod: user userfoo is currently logged in

 

$ who

myuser  pts/0        2018-08-17 11:29 (1.2.3.4)

 

$ ps aux | grep userfoo

root  16724  0.0  0.0 103236   884 pts/0    S+   11:36   0:00 grep userfoo

根本原因:chmod是根据lsof判断用户是否已经logged in的。通过lsof找出“正在登陆”的用户,kill掉相关进程就可以了。

$ lsof | grep userfoo

dbus-daem 29904       userfoo  cwd   unknown    /proc/29904/cwd (readlink: Permission denied)

dbus-daem 29904       userfoo  rtd   unknown    /proc/29904/root (readlink: Permission denied)

dbus-daem 29904       userfoo  txt   unknown    /proc/29904/exe (readlink: Permission denied)

dbus-daem 29904       userfoo NOFD              /proc/29904/fd (opendir: Permission denied)

dbus-daem 31889       userfoo  cwd   unknown    /proc/31889/cwd (readlink: Permission denied)

dbus-daem 31889       userfoo  rtd   unknown    /proc/31889/root (readlink: Permission denied)

dbus-daem 31889       userfoo  txt   unknown    /proc/31889/exe (readlink: Permission denied)

dbus-daem 31889       userfoo NOFD              /proc/31

相关阅读