Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.