Linux执行usermod时提示user xxx is currently logged in
近日遇到一怪事,执行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
myuserpts/0 2018-08-17 11:29 (1.2.3.4)
$ ps aux | grep userfoo
root167240.00.0 103236 884 pts/0 S+ 11:36 0:00 grep userfoo
根本原因:chmod是根据lsof判断用户是否已经logged in的。通过lsof找出“正在登陆”的用户,kill掉相关进程就可以了。
$ lsof | grep userfoo
dbus-daem 29904 userfoocwd unknown /proc/29904/cwd (readlink: Permission denied)
dbus-daem 29904 userfoortd unknown /proc/29904/root (readlink: Permission denied)
dbus-daem 29904 userfootxt unknown /proc/29904/exe (readlink: Permission denied)
dbus-daem 29904 userfoo NOFD /proc/29904/fd (opendir: Permission denied)
dbus-daem 31889 userfoocwd unknown /proc/31889/cwd (readlink: Permission denied)
dbus-daem 31889 userfoortd unknown /proc/31889/root (readlink: Permission denied)
dbus-daem 31889 userfootxt unknown /proc/31889/exe (readlink: Permission denied)
dbus-daem 31889 userfoo NOFD /proc/31
页:
[1]