无法使用 loginctl 终止用户会话

无法使用 loginctl 终止用户会话

我正在运行 lubuntu 20.04,并使用 sddm 作为显示管理器。

每当我通过 GUI 注销并以其他用户身份登录时,用户会话都不会被终止(不知道是否是设计使然)。因此 loginctl 会向我显示我的用户的双重会话。

我杀死的第 2 个用户的所有会话

killall -u second_user_name

对于我的主要用户来说,还剩下 3 个会话。

我可以删除具有最低会话 ID 的会话

sudo loginctl kill-session 3

剩下的

loginctl list-sessions 
SESSION  UID USER SEAT  TTY
     11 1000 alex seat0    
     21 1000 alex seat0    

下次尝试

alex@Guilmon:~$ sudo loginctl kill-session 11
[sudo] Passwort für alex: 
alex@Guilmon:~$ loginctl list-sessions 
SESSION  UID USER SEAT  TTY
     11 1000 alex seat0    
     21 1000 alex seat0    

2 sessions listed.
alex@Guilmon:~$ 


How can I get rid of it? Or avoid this situation (more than one session per user)

答案1

我想我找到了避免这种情况的方法。

/etc/systemd/logind.conf

KillUserProcesses=yes

来自手册页

KillUserProcesses=
           Takes a boolean argument. Configures whether the processes of a user should be killed when the user logs out. If true, the scope unit
           corresponding to the session and all processes inside that scope will be terminated. If false, the scope is "abandoned", see
           systemd.scope(5), and processes are not killed. Defaults to "no", but see the options KillOnlyUsers= and KillExcludeUsers= below.

           In addition to session processes, user process may run under the user manager unit [email protected]. Depending on the linger settings, this may
           allow users to run processes independent of their login sessions. See the description of enable-linger in loginctl(1).

           Note that setting KillUserProcesses=yes will break tools like screen(1) and tmux(1), unless they are moved out of the session scope. See
           example in systemd-run(1).
I restart 
    sudo systemctl restart systemd-logind.service 

1. 注销用户后,登录到 2. 用户后返回

alex@Guilmon:~$ loginctl 
SESSION  UID USER SEAT  TTY
     15 1000 alex seat0    

1 sessions listed.
alex@Guilmon:~$ 

不再等待在关机或重启期间停止因用户放弃会话而产生的某些事情。

相关内容