You are not logged in.

#1 2008-06-11 23:09:28

CBJ
Member
From: Denmark
Registered: 2006-03-12
Posts: 21

Tip: Automatic logout all users when reboot/halt over ssh

First the why:
OpenSSH on Debian automatically logs out users when you reboot or halt the server over SSH. This is rather nice, as it frees the terminal you ran ssh in for other jobs, instead of just waiting for respond from the server that has gone down.
How they did it I don't know, I have been unable to find any hints on it anyway.

Anyway, OpenSSH on Arch does not act this friendly and a Debian client hang for about 20 min before giving up. Debian's fault I think as an Arch client gives up long before that. Well you don't get it all with Debian... wink

Then the how:
After searching for a solution I ran into 'skill' that shout do the trick with this string:

# skill -KILL -v pts/*

However, it didn't work...

I could logout each user on his own with:

# skill -KILL -u [user]

But not very helpful either as a solution.
But remembering some sniplet I found on this forum for searching the license-string in installed packages, I made it find the users logged into the system with 'who' and throw them out:

who | cut -d " " -f1 | uniq | xargs skill -KILL -u

If you add this to /etc/rc.local.shutdown it will logout all users before the system goes down due to reboot or halt.
It works quite well on a desktop-system too... wink

I hope someone finds this helpful.

C

Offline

#2 2011-11-18 18:20:59

android
Member
From: San Diego
Registered: 2003-04-18
Posts: 160

Re: Tip: Automatic logout all users when reboot/halt over ssh

Thanks CBJ!

This is still working in 11/11 8-)

I added it to the "Tips and Tricks" section of the  SSH wiki page: https://wiki.archlinux.org/index.php/Se … s_shutdown

Offline

#3 2011-11-18 18:42:37

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Tip: Automatic logout all users when reboot/halt over ssh

Maybe you can do

users | xargs skill -KILL -u

or something like this.

[karol@black ~]$ who
test2    tty2         2011-11-18 19:38
karol    tty1         2011-11-16 23:34
[karol@black ~]$ who | cut -d " " -f1 
test2
karol
[karol@black ~]$ users
karol test2

Offline

#4 2011-11-18 19:48:40

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Tip: Automatic logout all users when reboot/halt over ssh

man skill wrote:

These tools are probably obsolete and unportable. The command syntax is poorly defined. Consider using the killall, pkill, and pgrep commands instead.

pkill -KILL -u
updated wiki for you


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#5 2011-11-18 20:34:32

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Tip: Automatic logout all users when reboot/halt over ssh

fsckd wrote:
man skill wrote:

These tools are probably obsolete and unportable. The command syntax is poorly defined. Consider using the killall, pkill, and pgrep commands instead.

pkill -KILL -u
updated wiki for you

Does it work for you? It does not work for me:

[karol@black ~]$ users
karol test1 test2
[karol@black ~]$ sudo pkill -KILL -u test1 test2
[karol@black ~]$ users
karol test1 test2
[karol@black ~]$ sudo skill -KILL -u test1 test2
[karol@black ~]$ users
karol

Offline

#6 2011-11-18 21:07:33

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Tip: Automatic logout all users when reboot/halt over ssh

What happens when you do pkill -KILL -u test1 ?


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#7 2011-11-18 21:11:17

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Tip: Automatic logout all users when reboot/halt over ssh

fsckd wrote:

What happens when you do pkill -KILL -u test1 ?

It works, but I'm wondering why specifying multiple users does not.

[karol@black ~]$ users
karol test1
[karol@black ~]$ sudo pkill -KILL -u test1
[karol@black ~]$ users
karol

Offline

#8 2011-11-18 21:20:14

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Tip: Automatic logout all users when reboot/halt over ssh

Who says it does not? wink


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#9 2011-11-18 21:34:23

wonder
Developer
From: Bucharest, Romania
Registered: 2006-07-05
Posts: 5,941
Website

Re: Tip: Automatic logout all users when reboot/halt over ssh

solution is to add in rc.conf NETWORK_PERSIST="yes". the idea is that networking is stopped and it doesn't kill the ssh connections and instead clients will timeout.


Give what you have. To someone, it may be better than you dare to think.

Offline

#10 2011-11-18 21:42:04

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: Tip: Automatic logout all users when reboot/halt over ssh

:confused:

Is wondering implying that one does NOT need this tweak in /etc/rc.local.shutdown if one sets the NETWORK_PERSIST="yes" in /etc/rc.conf?


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#11 2011-11-19 08:34:01

wonder
Developer
From: Bucharest, Romania
Registered: 2006-07-05
Posts: 5,941
Website

Re: Tip: Automatic logout all users when reboot/halt over ssh

exactly


Give what you have. To someone, it may be better than you dare to think.

Offline

#12 2011-11-19 11:44:21

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: Tip: Automatic logout all users when reboot/halt over ssh

Thanks wonder.  I'll edit the wiki page but is there a reason why this isn't an Arch default?

Last edited by graysky (2011-11-19 11:50:18)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB