You are not logged in.

#1 2013-01-30 03:21:44

artomason
Member
Registered: 2013-01-27
Posts: 19

[SOLVED] Gracefully logout all connected SSH users.

I was reading over the SSH Wiki about automatically logging off all SSH users when the daemon exits, however the fix that is provided is depreciated. I was wondering if there is another way to gracefully logoff all connected SSH users when the server is restarted, shutdown, or the daemon exits. Currently if any of the fore-mentioned actions take place no message is sent to the client to produce a "Disconnected" error message. This basically makes the ssh client appear like something froze on the server side.

Thanks!

- Aaron

Last edited by artomason (2013-02-07 20:22:48)

Offline

#2 2013-01-30 09:58:38

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

Re: [SOLVED] Gracefully logout all connected SSH users.

This is a gap. If you use netcfg see, https://wiki.archlinux.org/index.php/Ne … d_via_sshd


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

Offline

#3 2013-02-02 20:05:50

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

I don't suppose there is a way to do this without using netcfg?

Offline

#4 2013-02-02 20:13:39

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

Re: [SOLVED] Gracefully logout all connected SSH users.

Not to my knowledge.  I actually asked about this either in these forums or in the bug tracker.  The link above was the best solution at the time.  It seems like the sshd.service should handle this to me...


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

Offline

#5 2013-02-05 03:49:03

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

I think removing bash.bash_logout from /etc and .bash_logout from /home/$USER/ seemed to do the trick, but I'm not completely sure. Both of the files were empty but I did not keep a backup when I removed them, which I should have to test this fix. Can someone give this a try and see if it worked for them?

Offline

#6 2013-02-05 08:44:16

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: [SOLVED] Gracefully logout all connected SSH users.

sshd.service cannot inform the client that it is shutting down:
it is being stopped when the network is already down, so it has no way to reach the client.

You must configure your network service (netcfg, NetworkManager, ... ) to stop sshd.service before bringing down the network.

Offline

#7 2013-02-05 12:28:45

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

The problem is that I'm not using netcfg or Network Manager. Once I removed the above mentioned, things started working as I originally intended them too. I'm sure in the case of using netcfg or Network Manager I would have to configure sshd to drop before deconfiguring the network interface. I think I might try to modify the sshd.service to do this but I'm going to have to play around with it to get it working. I don't suppose there is a way to make your network.service wait until all the other services that require it are shutdown first.

Offline

#8 2013-02-05 13:50:12

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

Re: [SOLVED] Gracefully logout all connected SSH users.

Dunno.  Use netctl which seems to be the future anyway.  It is currently in the AUR.  Read the arch projects ML for more.  I should add the netctl uses the same profiles as netcfg.


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

Offline

#9 2013-02-05 23:32:19

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

Thanks for the info. I'm pretty new to arch. Debian pretty much just had one way to get things done.

Offline

#10 2013-02-07 19:55:59

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

Wel, the old behavior is back.

From my understanding of the problem at hand, systemd brings down the sshd.service and network.service, but the SSH connections are never killed. Instead the connection just hangs until the TCP timeout is reached in which case you will get a software connection error if you are using Putty. It would *NOT* be recommended to create a script within SSHD to kill all connections whenever the SSHD is stopped or restarted due to the fact that there are situations where you need to restart the daemon while logged in via SSH, without killing your own connection.

On the other hand it may be possible to create a script that is executed whenever the system is restarted or shutdown that would canvas the system for logged in SSH users and kill the connections, however I do not have the foggiest idea where to start or how to go about doing this, and that is if it is even possible via systemd or some other means.

Anyone have any other suggestions?

On a side note, there are quite a few bugs listed for this specific problem on different distributions, however no solutions were mentioned.

Offline

#11 2013-02-07 20:22:08

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

Found a fix for this type of behavior

edit /lib/systemd/system/systemd-user-sessions.service and append network.target to the after line.

[Unit]
Description = Permit User Sessions
Documentation = man:systemd-user-sessions.service(8)
After = network.target remote-fs.target

then symlink /lib/systemd/system/systemd-user-sessions.service to /etc/systemd/system/

Hope this helps someone else.

Last edited by artomason (2013-02-07 20:34:11)

Offline

#12 2013-02-07 21:32:12

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

Re: [SOLVED] Gracefully logout all connected SSH users.

@artomason - You should open a feature request against systemd if you feel this is a general solution.


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

Offline

#13 2013-02-08 02:43:30

artomason
Member
Registered: 2013-01-27
Posts: 19

Re: [SOLVED] Gracefully logout all connected SSH users.

I don't have the link anymore, but from my understanding this is already in the works for the next upstream version.

Offline

#14 2013-02-08 12:27:20

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

Re: [SOLVED] Gracefully logout all connected SSH users.

artomason wrote:

I don't have the link anymore, but from my understanding this is already in the works for the next upstream version.

Would be great to confirm so that the wiki pages that teach the method I suggested above can be edited.


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

Offline

#15 2013-02-08 14:57:58

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: [SOLVED] Gracefully logout all connected SSH users.

artomason wrote:

Found a fix for this type of behavior

edit /lib/systemd/system/systemd-user-sessions.service and append network.target to the after line.

[Unit]
Description = Permit User Sessions
Documentation = man:systemd-user-sessions.service(8)
After = network.target remote-fs.target

then symlink /lib/systemd/system/systemd-user-sessions.service to /etc/systemd/system/

Hope this helps someone else.

This was already rejected upstream: http://lists.freedesktop.org/archives/s … 06900.html


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

Board footer

Powered by FluxBB