LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   SSH disconnects when inactive (https://www.linuxquestions.org/questions/linux-networking-3/ssh-disconnects-when-inactive-921162/)

deep27ak 12-29-2011 11:26 PM

SSH disconnects when inactive
 
Hello All,

I am using RHEL 5.2 and this is quite surprising situation when I use putty to connect to my remote machine it regularly gets disconnected when kept inactive for few minutes then I need to relogin to start my work.

But again this happens with only one server and all the other servers in which I login, there is no such problem.

I did a bit google and came up with this site

http://www.walkernews.net/2008/05/11...-disconnected/

But my concern is why ut happens with only one server?

Is my sshd_config has any thing to do with it?
Kindly tell me where to look out for the solution

fukawi1 12-29-2011 11:33 PM

Some things to check in sshd_config

TCPKeepAlive, ClientAliveCountMax, ClientAliveInterval.

deep27ak 12-29-2011 11:48 PM

Quote:

Originally Posted by fukawi1 (Post 4561481)
Some things to check in sshd_config

TCPKeepAlive, ClientAliveCountMax, ClientAliveInterval.

Hii fukawi1,

Thanks for the reply

I know about these things but I want to know why this happens with only one server and not others

as I checked sshd_config of other machines as well and I don't see any changes but the only difference is they seem to work properly and never gets disconnected?

fukawi1 12-30-2011 12:12 AM

try tailing the secure log in one session
Code:

tail -f /var/log/secure
then start a new session and let it drop out. and check if the log has anything useful to say.

I havent used putty in years so i dont know much about it now, but as your link suggests, it may be doing something to disconnect after inactivity.. What happens if you ssh from a different linux host to the problematic one? (to isolate if it is a putty/client, or server problem.

deep27ak 12-30-2011 04:56 AM

Quote:

Originally Posted by fukawi1 (Post 4561502)
try tailing the secure log in one session
Code:

tail -f /var/log/secure
then start a new session and let it drop out. and check if the log has anything useful to say.

I havent used putty in years so i dont know much about it now, but as your link suggests, it may be doing something to disconnect after inactivity.. What happens if you ssh from a different linux host to the problematic one? (to isolate if it is a putty/client, or server problem.

this is the output of command you mentioned

Code:

Dec 19 21:35:28 server sshd[2741]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=10.10.10.30  user=root
Dec 19 21:35:30 server sshd[2741]: Failed password for root from 10.10.10.30 port 52162 ssh2
Dec 19 21:35:32 server sshd[2741]: Accepted password for root from 10.10.10.30 port 52162 ssh2
Dec 19 21:35:32 server sshd[2741]: pam_unix(sshd:session): session opened for user root by (uid=0)
Dec 19 21:51:05 server sshd[2741]: pam_unix(sshd:session): session closed for user root
Dec 19 21:52:10 server sshd[2799]: Accepted password for root from 10.10.10.30 port 52312 ssh2
Dec 19 21:52:10 server sshd[2799]: pam_unix(sshd:session): session opened for user root by (uid=0)
Dec 19 22:07:15 server sshd[2799]: pam_unix(sshd:session): session closed for user root
Dec 20 02:44:55 server sshd[3320]: Accepted password for root from 10.10.10.30 port 59671 ssh2
Dec 20 02:44:55 server sshd[3320]: pam_unix(sshd:session): session opened for user root by (uid=0)

and even I tried from ssh
the session gets disconnected in a while with this error message
Code:

Read from remote host 192.168.0.195: Connection reset by peer
Connection to 192.168.0.195 closed.


fukawi1 12-30-2011 05:23 AM

Nothing stands out to me there...
But a couple more ideas worth trying..

To get more info out of the error. try adding -vvv to the ssh command. and stopping the sshd process on the server, and running it from the commandline with debugging increased.
Code:

sshd -ddd &
adding -e will make ssd show errors on screen rather than log them, if your sitting at the screen.

Is the shell inactivity timeout set to something silly? IIRC 0, means the shell wont time out. On the ssh SERVER, run the below, it can be set permenantly in .bashrc.
Code:

echo $TMOUT
Could it be ACPI powering down a disk, or something, the delay of it powering back up causing the dropout?

Is there a firewall inbetween the client and server, that could be dropping inactive connections?

Just some food for thought anyway...

deep27ak 12-30-2011 05:39 AM

I changed the
Code:

ClientAliveInterval 300

ClientAliveCountMax 5

but still same issue
I'll try your steps but today office time over so will get back on monday till then

HAPPY NEW YEAR :)

deep27ak 01-03-2012 11:34 PM

Now I did some changes

Code:

ClientLiveInterval 60
ClientAliveCountMax 5

and now I think the ssh is not getting disconnected when kept idle

I logged in using
Code:

#ssh -vvv 192.168.0.195
and now when I leave the console idle for few minutes, this is something which I get and am unable to understand if you can throw some light on it

Code:

[root@server ~]# debug1: client_input_channel_req: channel 0 rtype keepalive@ope                                                                                        nssh.com reply 1
debug1: client_input_channel_req: channel 0 rtype keepalive@openssh.com reply 1
debug1: client_input_channel_req: channel 0 rtype keepalive@openssh.com reply 1
debug1: client_input_channel_req: channel 0 rtype keepalive@openssh.com reply 1

does it means that ssh itself is sending packets after every 1 min to keep the session alive as I have mentioned in sshd_config?

But still even if the problem is solved I don't get any answer to my question that why it happens only on one server where all other session works fine without any changes?

I also tried adding this line
Code:

ServerAliveInterval 60
but while restarting it returns with a error
Code:

Bad configuration option: ServerAliveInterval
Is it some where related to version of ssh or distribution support?

fukawi1 01-03-2012 11:47 PM

Quote:

Originally Posted by deep27ak (Post 4565418)
does it means that ssh itself is sending packets after every 1 min to keep the session alive as I have mentioned in sshd_config?

Yes, you wont see the debug messages when ssh'ing normally (ie: without -vvv)

Quote:

But still even if the problem is solved I don't get any answer to my question that why it happens only on one server where all other session works fine without any changes?
That, I'm not sure about, what is the server doing? is it under heavy system load, or traffic load perhaps?

Quote:

Is it some where related to version of ssh or distribution support?
ServerAliveInterval, is effectively the same as ClientAliveInterval, except in the other direction, it is set in the clients ssh_config.

deep27ak 01-04-2012 12:39 AM

Quote:

Originally Posted by fukawi1 (Post 4565424)
That, I'm not sure about, what is the server doing? is it under heavy system load, or traffic load perhaps?


No, that is my mail server and is touched only when required to make any changes in the config file.

Do you have any possible ideas which might be the reason for such issue?
I have installed sendmail+apache+squirrelmail on this server and nothing else
But it seems while restarting ssh is unable to recognise the syntax used for ServerAliveInterval

does it has anything to be done with distro used?

fukawi1 01-04-2012 03:16 AM

Quote:

Originally Posted by deep27ak (Post 4565457)
Do you have any possible ideas which might be the reason for such issue?

Not really, i guess there could be any number of reasons, but I cant see any obvious ones in this situation.

Quote:

But it seems while restarting ssh is unable to recognise the syntax used for ServerAliveInterval
does it has anything to be done with distro used?
As i said in my last post, ServerAliveInterval, is set in ssh_config, on the client machine.
ClientAliveInterval, is set in sshd_config, on the server.
I believe that to be the same for all distro's.

deep27ak 01-04-2012 03:20 AM

Quote:

Originally Posted by fukawi1 (Post 4565551)

As i said in my last post, ServerAliveInterval, is set in ssh_config, on the client machine.
ClientAliveInterval, is set in sshd_config, on the server.
I believe that to be the same for all distro's.

oops, sorry my mistake
Yes its working when placed in ssh_config

Well, Thanks for your help :)


All times are GMT -5. The time now is 08:48 AM.