LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 09-16-2014, 03:51 PM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
How to set SSH idle timeout


Say someone starts a SSH session through Putty to a CentOS box, and they leave it sit idle for a while. Where can I set an idle timeout so it will disconnect any sessions idle for a certain time period?
 
Old 09-16-2014, 04:11 PM   #2
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
rjo98,

In the /etc/ssh/sshd_config file, uncomment and change the ClientAliveInterval, then restart the sshd services. According to the MAN page of sshd_config:

ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message
through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will
not be sent to the client. This option applies to protocol version 2 only.


ClientAliveInterval 60 would drop the connection after 60 seconds of inactivity.
 
2 members found this post helpful.
Old 09-16-2014, 04:14 PM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
great, thanks!
 
Old 09-16-2014, 04:20 PM   #4
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
Glad to help!! You may have to watch for the users though!! They can set their own /etc/ssh/ssh_config and add the line:

ServerAliveInterval 60

and send keepalives to the server every 60 seconds and get around that..... pesky kids!
 
1 members found this post helpful.
Old 09-16-2014, 04:29 PM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
hahaha, i'll keep my eyes peeled for that little trick.
 
Old 09-16-2014, 04:41 PM   #6
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Looking on some older servers, I don't see that option set but they do disconnect. Was that maybe enabled by default or something in older versions of ssh?
 
Old 09-17-2014, 07:25 AM   #7
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
ServerAliveInterval 60 is a line the client can add to their /etc/ssh/ssh_config rather than on the servers /etc/ssh/sshd_config
 
Old 09-17-2014, 07:39 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I never touch the server's sshdd_config for this issue.
I have used in my ~/.ssh/config
Code:
Host *
ServerAliveInterval 120
ServerAliveCountMax 30
ConnectTimeout 30
and I can idle for days.
 
Old 09-17-2014, 11:01 AM   #9
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
ok, because looking at another server, I don't see that setting configured in the main config file, and in the user's ~/.ssh/ I don't see a config file. I think I'm either missing something, or maybe there's another way to cause a similar outcome? or it was just a default setting in older versions that did it no matter what, which is why I can't find it. not a big deal, i'm just confused.
 
Old 09-17-2014, 11:52 AM   #10
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 99
Actually, it was my mistake... that line gets added to /etc/ssh/ssh_config... not ~/.ssh/ssh_config

This still requires root access, but I was referring to "users" just as the client machine rather than the actual user's access/permissions...
 
Old 09-17-2014, 11:54 AM   #11
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Ah ok, so it's only the global setting in the main config file then. Still makes me wonder why other older servers will disconnect an idle ssh session if they don't have that set. Maybe there's a different setting out there that disconnect any idle connect (not connection type specific).
 
Old 09-17-2014, 03:15 PM   #12
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
maybe it's the shell killing the session on those other servers. I'm going to test it again, but on this new server, I don't think it's killing sessions either with only ClientAliveInterval set. maybe i need to enable another setting in there that goes with it.

I'll post back if i've gone crazy and idle sessions actually are killed with just that setting
 
  


Reply



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
Tweaking the idle/shutdown timeout valunthar Linux - Server 0 01-29-2012 04:18 PM
[C] ssh idle timeout noir911 Programming 3 03-17-2009 03:27 AM
[SOLVED] set timeout for ssh prompt vikas027 Programming 2 04-22-2008 03:35 PM
idle timeout for linux console car182 Linux - Security 1 10-17-2006 04:43 PM
Idle timeout. bulzbb Linux - General 3 03-13-2004 06:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:57 PM.

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