Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a SFTP server, where clients connect every minute to exchange files. There are few clients who connect and then dont disconnect resulting in a lot of connections over a period of time. This is choking up the CPU. I have set ClientAliveInterval and ClientAliveCountMax in sshd_config which disconnects idle ssh connection after a certain period, but id doesnt seem to disconnect the idle sftp connections. How do I force idle sftp connections to disconnect?

share|improve this question
Truly idle connections don't choke up the CPU or much of anything else. – Michael Hampton Jan 19 '13 at 16:57

Try this step by step:

pstree -p -- the whole process tree will be displayed.

w - Who is doing what. - may be this will not be necessary (or maybe you can get the idle times for the users.)

ps aux| grep sshd

Try to get the process id of sshd session, which is the parent process of the sftp server. You can get a user's sftp process id from ps aux | grep sshd, the kill its parent process:

ps output will be like:

root@server:/# ps aux | grep ssh
root      3531  0.0  0.0   5312  1012 ?        Ss   Jan02   0:00 /usr/sbin/sshd
root     24034  0.0  0.1   8052  2412 ?        Ss   13:24   0:00 sshd: metin [priv]
metin    24039  0.0  0.0   8052  1500 ?        S    13:24   0:00 sshd: metin@notty
metin    24042  0.0  0.0   4568  1240 ?        Ss   13:24   0:00 /usr/lib/openssh/sftp-server
root     24043  0.0  0.1   8052  2632 ?        Ss   13:24   0:00 sshd: metin [priv]
metin    24048  0.0  0.0   8052  1532 ?        S    13:24   0:00 sshd: metin@pts/0
root     24109  0.0  0.0   3000   748 pts/0    R+   13:26   0:00 grep ssh

pstree -p output will be like:

        │               ├─apache2(23846)
        │               ├─apache2(23913)
        │               ├─apache2(23998)
        │               ├─apache2(24000)
        │               ├─apache2(24025)
        │               ├─apache2(24028)
        │               ├─apache2(24073)
        │               ├─apache2(24074)
        │               └─apache2(24075)
        │                                         ├─authdaemond(3736)
        │                                         ├─authdaemond(3738)
        │                                         ├─authdaemond(3740)
        │                                         └─authdaemond(3741)
        │              ├─qmgr(3885)
        │              └─tlsmgr(4144)
        │                   └─mysqld(3633)─┬─{mysqld}(3637)
        │                                  ├─{mysqld}(3638)
        │                                  ├─{mysqld}(3639)
        │                                  ├─{mysqld}(3640)
        │                                  ├─{mysqld}(3642)
        │                                  ├─{mysqld}(3643)
        │                                  ├─{mysqld}(3644)
        │                                  ├─{mysqld}(3655)
        │                                  ├─{mysqld}(861)
        │                                  ├─{mysqld}(17322)
        │                                  ├─{mysqld}(18125)
        │                                  ├─{mysqld}(18872)
        │                                  ├─{mysqld}(21229)
        │                                  ├─{mysqld}(23352)
        │                                  ├─{mysqld}(23353)
        │                                  └─{mysqld}(23370)
        │             ├─{named}(3505)
        │             └─{named}(3506)
        │                 ├─saslauthd(3914)
        │                 ├─saslauthd(3915)
        │                 └─saslauthd(3916)
        │          ├─sshd(24043)───sshd(24048)───bash(24050)───su(24077)───bash(24078)───ps+
        │            └─sshd(24094)───sshd(24099)───sftp-server(24101)

And you're going to do kill 24034, because it is parent sshd session for the process user "metin" have been using as process 24042 (take a look at ps output above).

And also you can get their status (Idle, sleep, active and etc.) from the output of the ps.

If you want to do this automatically, I don't know any software for this, but you can write your own script.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.