LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-21-2016, 09:12 PM   #1
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Rep: Reputation: 135Reputation: 135
behavior of ServerAliveInterval with ssh connection


Hi experts,

Using ssh I am logging to another system and executing scripts there that creates new machines, and do some setups. It takes around 7-8 hours. So what happened the ssh connection keeps dropping and I always get timeout with unsuccessful execution of the script.

So now I am using this argument along with ssh connection:

Code:
"ssh -o ServerAliveInterval=60 user@host ...."
This ssh is invoked multiple times. The problem is after few ssh connection, I am getting error :

Quote:
too many logins of user
and the after ssh connections are getting closed after successful logins.

So is it the behavior of the ServerAliveInterval, that keeps the ssh user login session in remote machine alive even after ssh work is over and that's why my further logins are disconnected ?

Last edited by divyashree; 10-21-2016 at 10:47 PM.
 
Old 10-22-2016, 02:31 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,293
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
ServerAliveInterval, used with ServerAliveCountMax, send a message over the encrypted channel and then officially disconnect if the limits for lack of response are exceeded. See the manual page of ssh_config for more. It won't produce any error message other than indicating that the connection is dropped. Maybe ServerAliveCountMax needs to be increased.

Regardless, if your connection is likely to break during a long task, I'd work with a terminal multiplexer like "tmux" or "screen". When you log in the first time, start "tmux" then start your task. If you get disconnected, log in again and reconnect with "tmux a".

The error "too many logins of user" is something else that is in the way and not SSH itself, at least it's not Open SSH server. Does your server have some kind of rate limiting like "sshguard" or "fail2ban" installed?
 
Old 10-24-2016, 12:41 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Thanks Turbocapitalist
Quote:
Originally Posted by Turbocapitalist View Post
ServerAliveInterval, used with ServerAliveCountMax, send a message over the encrypted channel and then officially disconnect if the limits for lack of response are exceeded.
So if I am not using ServerAliveCountMax along with ServerAliveInterval, will the sessions stay alive forever ?
 
Old 10-24-2016, 04:10 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,293
Blog Entries: 3

Rep: Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718Reputation: 3718
Quote:
Originally Posted by divyashree View Post
So if I am not using ServerAliveCountMax along with ServerAliveInterval, will the sessions stay alive forever ?
If the TCP connection is broken or unreliable, the SSH connection will eventually hang in practice. If you have ServerAliveCountMax and ServerAliveInterval set, then at least you know when the connection is no longer there in practice. If you use a terminal multiplexer like "tmux" then you can recover seamlessly. You'll need to use keys and a key agent for optimal performance.

Code:
while ! ssh -i ~/.ssh/some_key_rsa -t server.example.com 'tmux a || tmux'; do sleep 2; done
A similar trick can be done with "screen" if you do not have "tmux" and cannot install it.
 
Old 10-24-2016, 04:45 AM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by divyashree View Post
This ssh is invoked multiple times. The problem is after few ssh connection, I am getting error
How many connections you need to the server?
Try just one or two sessions and see if the situation persists.
 
  


Reply

Tags
linux client, ssh localhost remote


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
Interesting Behavior sumncguy Linux - Newbie 1 10-07-2014 08:01 AM
Array behavior piyush.sharma Programming 12 08-08-2012 03:21 AM
NTP behavior thllgo Linux - Server 9 01-24-2011 12:22 PM
Weird behavior Bassy Linux - Software 2 10-20-2005 01:32 PM
ls -l behavior vjl323 Mandriva 3 11-05-2003 07:30 AM

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

All times are GMT -5. The time now is 07:06 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