LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-10-2014, 04:51 AM   #1
jojanmpaul
Member
 
Registered: Sep 2012
Location: Bangalore
Posts: 80

Rep: Reputation: Disabled
Handle ssh sessions


I have got a more than 1000 ssh connection to one server, how to kill all without restarting the service.

kill -9 PID is difficult to handle with this issue.

ssh connections,

lsof -i :22 | wc -l
1241

Is there any way to control ssh sessions like, by finding and kill the inactive sessions.
 
Old 01-10-2014, 06:48 AM   #2
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
Actually, that's 2 different questions.
1) Kill all without restarting the service: "killall ssh"
The service is named 'sshd' so it should still run. (And of course, test this first!)

2) Kill the inactive sessions
This is different and a bit more tricky.
But the first thought is, why are inactive sessions not dropped? This you should look into, manually killing inactive sessions is just a work-around until real problem is solved.
To find the inactive sessions you'll have to define "inactive", a session idle for how long?
Then use the command "w" and check the IDLE column. It will tell you username & TTY, you will have to use for example "ps -e" with grep to get the PID.
You could then create a script that finds & kills all sessions that have been idle for X minutes.

Last edited by pingu; 01-10-2014 at 06:52 AM.
 
1 members found this post helpful.
Old 01-10-2014, 06:55 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,305

Rep: Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816
Quote:
Originally Posted by pingu View Post
To find the inactive sessions you'll have to define "inactive", a session idle for how long?

You could then create a script that finds & kills all sessions that have been idle for X minutes.
Good advice.

However, it becomes really fun trying to decide what really is "idle", is a session running "top" for 2 hours idle or is it someone monitoring something?
 
Old 01-10-2014, 08:56 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Not to mention, is it idle when a user has a forwarded X application?

Is it idle if no tty is associated with the session?
 
Old 01-10-2014, 09:14 AM   #5
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Just kill em all and let god sort them out.

Last edited by zhjim; 01-10-2014 at 10:51 AM.
 
1 members found this post helpful.
Old 01-10-2014, 09:57 AM   #6
laz000
LQ Newbie
 
Registered: Nov 2004
Location: SE US
Distribution: Slackware, RHEL, CENTOS, Fedora FreeBSD
Posts: 4

Rep: Reputation: 0
Configure ssh daemon

In /etc/ssh/sshd_config you could insert

ClientAliveInterval 300
ClientAliveCountMax 3


That will give you an timeout of 15 minutes = 300 sec x 3 checks
 
Old 01-10-2014, 10:24 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
That identifies network outages, or remote client failures.

It is possible that is what is happening though (it is also supposed to be the default, but individual distribution variations could have it turned off).
 
  


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
is there a way to restrict ssh sessions to a specific ssh client? smbhat Linux - Networking 8 03-11-2009 08:36 AM
[priv] in SSH Sessions stefaandk Linux - Security 2 09-22-2006 01:05 PM
SSH and SFTP sessions BigLar Linux - General 3 04-26-2006 11:18 AM
SSH help, concerning sessions frokid879 Linux - Newbie 4 11-11-2005 12:22 PM
dead ssh sessions babroga Linux - Newbie 1 03-03-2002 09:16 AM


All times are GMT -5. The time now is 04:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration