LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   disconnect idle ssh sessions (https://www.linuxquestions.org/questions/linux-newbie-8/disconnect-idle-ssh-sessions-596009/)

pinoyskull 10-31-2007 02:28 AM

disconnect idle ssh sessions
 
Hi,

Is there a better way to disconnect idle ssh clients, what I did is to look for the PID of the idle session then kill it. If you have a better way of doing it.

Idle ssh sessions that I encounter usually has an idle time of 1 day above.

keratos 10-31-2007 04:33 AM

Add these lines to your ssh config file (sshd is the daemon for ssh) usually /etc/ssh/sshd_config. (not sure about fedora!)

ClientAliveInterval <time interval in seconds>
ClientAliveCountMax 0

Restart sshd (try the command "service sshd reload" as root)

Code:

From the sshd_config manpage:

    ClientAliveInterval
            Sets a timeout interval in seconds after which if no data has
            been received from the client, sshd will send a message through
            the encrypted channel to request a response from the client.  The
            default is 0, indicating that these messages will not be sent to
            the client.  This option applies to protocol version 2 only.

Example (send "keep alive" messages every 5 minutes) on Red Hat Linux:

1. Add ClientAliveInterval 300 to /etc/ssh/sshd_config

2. Reload the sshd server configuration with /sbin/service sshd reload

Note: you may want to configure the ClientAliveCountMax value in sshd_config to set the number of times that "keep alive" messages are sent. If ClientAliveCountMax number of "keep alive" messages are not acknowledged by the ssh client, the connection is terminated by the ssh server. The default value of 3 should be sufficient for most users.


pinoyskull 11-03-2007 01:45 AM

keratos

tried that method but idle ssh sessions still wont disconnect

keratos 11-03-2007 04:18 AM

Is your client sending a "keep alive" to the ssh server.

I cant think of anything else, sorry?

pinoyskull 11-03-2007 04:35 AM

Quote:

Originally Posted by keratos (Post 2946620)
Is your client sending a "keep alive" to the ssh server.

I cant think of anything else, sorry?

those users whose ssh session did not disconnect on the remote servers are using putty for windows, which after they logout the putty program is closed.

keratos 11-04-2007 03:03 AM

putty can be (and usually is) configured to send "keep-alives".

Did you check this?

pinoyskull 11-06-2007 07:54 PM

Quote:

Originally Posted by keratos (Post 2947585)
putty can be (and usually is) configured to send "keep-alives".

Did you check this?

yeah, it is configured to send "keep-alives" but when you close putty, should it still send "keep-alives"?

keratos 11-07-2007 06:49 AM

No

not unless it is still running or something else is sending keepalives.

something MUST be using the connection.

check your IP traffic on your host - something must be sending traffic down the line.

pinoyskull 11-08-2007 11:16 PM

here's the screenshot
http://i20.photobucket.com/albums/b2...reenshot-3.png
as you can see those sessions which are idle for days should be disconnected already since no more ssh client are open on their pc.

pinoyskull 11-09-2007 12:26 AM

after digging the internet for possible solutions, I finally got one and it works

i added TMOUT=300 to /etc/bashrc to disconnect users which are idle for 5 minutes

keratos 11-09-2007 03:10 AM

Quote:

Originally Posted by pinoyskull (Post 2952883)
here's the screenshot
http://i20.photobucket.com/albums/b2...reenshot-3.png
as you can see those sessions which are idle for days should be disconnected already since no more ssh client are open on their pc.

that looks like a screenshot of a "top" command, and not an IP traffic analyser.

Putting the timeout in a bashrc is extreme as it will disconnect at the client end rather than the server end. But if you are happy with this , fine , I personally would find out what the issue is and fix it correctly.

Closing down login shells just to disconnect from the ssh server is extreme in my view and may shut users down who are not even using ssh and they will wonder why? Not the sort of thing a good sysadmin would do, in my humble view.

pinoyskull 11-09-2007 03:23 AM

From what i read, bashrc tmout setting will only disconnect idle sessions of telnet and ssh and nothing more, by the way that is not "top" that is "w".

keratos 11-09-2007 03:29 AM

Incorrect!!!

http://www.gnu.org/software/bash/manual/bashref.html

search for "TIMEOUT" - its all there!

and top / w , not too much difference , generally process/user related , I can't get excited about the difference suffice to say it IS NOT as I proposed you obtain, which was a list of IP traffic and sink/sources to establish what and who is sending, if at all, keepalives to the ssh server.

Anyway, you're happy now.

Byeeeeee

pinoyskull 11-09-2007 03:56 AM

so, what do you think are affected by bashrc's tmout setting aside from your shell?

keratos 11-09-2007 04:27 AM

Quote:

Originally Posted by pinoyskull (Post 2953043)
so, what do you think are affected by bashrc's tmout setting aside from your shell?

Why of course, any application that is invoked from or through the shell.

As stated above, in my humble view, killing the shell this way is not what a sysadmin would probably do. Its an overkill. Any user who is dropped into a bash shell will find themselves mysteriously logged out after "a period of inactivity".

If I were a sysadmin, I would wonder why anyone had took a sledgehammer to a nut in this way.

pinoyskull 11-09-2007 04:47 AM

As of this moment, this is the only method that works since your suggestion on sshd_config wont work on my system, there's must be something wrong with the server because it wont work but i dont want to do anything critical at the moment because this is a production server, anyway this is scheduled to be replaced with a new version of fedora since it is still running of fc2.

keratos 11-09-2007 05:05 AM

FC2 - WoW! yawn.

The instructions are not mine, they are sshd standard instructions.

As I said, and I'm slightly yawning now, you should establish what IP traffic there is to the server. You STILL have not instigated this investigation and yet deem it appropriate to apportion an element of dissatisfaction on my assistance.

I give up!

sergi_the_geek 03-01-2010 11:22 AM

typing EXIT like at the windows command line simply killed it for me!

Tinkster 03-01-2010 11:54 AM

Hi Sergi, welcome to LQ!

Can you please in the future try not to reanimate threads that
were dead for several years?

Specially if your contribution doesn't address the OPs problem.


Cheers,
Tink

sergi_the_geek 03-02-2010 03:29 AM

Hi Yes sorry, distracted train of thought, apologies to all.


All times are GMT -5. The time now is 06:28 PM.