LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-03-2012, 09:15 PM   #1
nuliknol
Member
 
Registered: Jul 2009
Posts: 42

Rep: Reputation: 0
close dead ssh connections


I have a DSL modem internet connection at home and when I am logged in to my dedicated internet server using ssh, the modem times out my connections when they are idle. The result is, I am accumulating dead ssh connections being idle for days (wasting system resources) that I have to kill with -9 periodically. This is how they look like when I ps:

Code:
....
root     13610  0.0  0.1   5084  1160 ?        S    Apr02   0:00 su -c /usr/bin/xterm
root     13612  0.0  0.2   8104  2364 ?        S    Apr02   0:00  \_ /usr/bin/xterm
root     13616  0.0  0.1   4772  1388 pts/29   Ss+  Apr02   0:00      \_ bash
root     14091  0.0  0.1   5084  1156 ?        S    Apr02   0:00 su -c /usr/bin/xterm
root     14093  0.0  0.2   8100  2488 ?        S    Apr02   0:00  \_ /usr/bin/xterm
root     14095  0.0  0.1   4768  1448 pts/30   Ss+  Apr02   0:00      \_ bash
root     22160  0.0  0.1   5084  1164 ?        S    Apr02   0:00 su -c /usr/bin/xterm
root     22162  0.0  0.2   8100  2480 ?        S    Apr02   0:00  \_ /usr/bin/xterm
root     22164  0.0  0.1   4768  1384 pts/32   Ss+  Apr02   0:00      \_ bash
root      6946  0.0  0.1   5084  1156 ?        S    Apr03   0:00 su -c /usr/bin/xterm
root      6948  0.0  0.2   8100  2360 ?        S    Apr03   0:00  \_ /usr/bin/xterm
root      6950  0.0  0.1   4768  1388 pts/25   Ss+  Apr03   0:00      \_ bash
root     16522  0.0  0.1   5084  1160 ?        S    Apr03   0:00 su -c /usr/bin/xterm
root     16524  0.0  0.2   8100  2484 ?        S    Apr03   0:00  \_ /usr/bin/xterm
root     16526  0.0  0.1   4772  1392 pts/36   Ss+  Apr03   0:00      \_ bash
root     22133  0.0  0.1   5088  1156 ?        S    Apr03   0:00 su -c /usr/bin/xterm
root     22135  0.0  0.2   8100  2364 ?        S    Apr03   0:00  \_ /usr/bin/xterm
root     22137  0.0  0.1   4768  1388 pts/40   Ss+  Apr03   0:00      \_ bash
root     28787  0.0  0.1   5084  1156 ?        S    Apr03   0:00 su -c /usr/bin/xterm
root     28789  0.0  0.2   8100  2488 ?        S    Apr03   0:00  \_ /usr/bin/xterm
root     28791  0.0  0.1   4768  1388 pts/43   Ss+  Apr03   0:00      \_ bash
[root@newze ~]#
I know I can setup ssh client with keep-alive and it will send some data to avoid the connection being expired by the firewall of the modem, but I don't want this (since it is not a clean solution). I want the ssh daemon to kill idle connections and the resulting child processes automatically after some inactivity period (which I can configure somewhere). Is this possible?

My OS is a bit old: centos-release-5-2.el5.centos , hope this is not an issue, I just can't upgrade this server right now, its a productive environment.

Will appreciate any comments very much on this case.
Thanks
 
Old 04-03-2012, 11:48 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Actually, setting ServerAliveInterval 30 (or some such) in your client-side ~/.ssh/config is a clean solution, IMO.

If that's still a no-go, then just let bash(1) time out your session. In your server-side ~/.bash_profile, set TMOUT=600 (or similar).
 
Old 04-04-2012, 09:45 AM   #3
nuliknol
Member
 
Registered: Jul 2009
Posts: 42

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by anomie View Post
Actually, setting ServerAliveInterval 30 (or some such) in your client-side ~/.ssh/config is a clean solution, IMO.
it is not clean because if the modem is reset and new ip is assigned, the connections will remain on the server side.

Quote:

If that's still a no-go, then just let bash(1) time out your session. In your server-side ~/.bash_profile, set TMOUT=600 (or similar).
this one looks good. thanks!
 
Old 04-04-2012, 10:00 AM   #4
nuliknol
Member
 
Registered: Jul 2009
Posts: 42

Original Poster
Rep: Reputation: 0
I found it, ClientAliveInterval configured on the server in sshd_conf should do what I need. Testing...
 
Old 04-04-2012, 06:42 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by nuliknol
it is not clean because if the modem is reset and new ip is assigned, the connections will remain on the server side.
If that's a regular concern, then consider using GNU screen or tmux.

I often work during my bus ride in to work. (The connection quality is terrible, and is dropped at least once during the ride.) With tmux, I simply re-attach session when the connection is active again.

Last edited by anomie; 04-04-2012 at 06:43 PM.
 
Old 04-04-2012, 07:25 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Also see Autossh to re-establish connections automagically.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] (Dead?) Active connections showing in Firestarter 1.0.3 taylorkh Linux - Security 2 02-28-2010 04:12 PM
how to close a socket and refuse waiting connections? hboosh Programming 2 01-05-2010 03:59 AM
Dead fisical connections, with telnet sessions. dryajov Linux - Networking 0 01-21-2005 11:41 AM
How do I close TIME_WAIT connections? linuxboy69 Linux - Software 2 09-01-2004 05:13 PM
Recompiled kernels and dead network connections. ritz22 Linux - Networking 4 05-25-2002 05:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration