Linux system prevents SSH agent from idle disconnect issues

Source: Internet
Author: User
Tags ssh ssh server

System: CentOS 5.9
1. Install expect
Yum-y Install expect


2. Configure the anti-SSH agent disconnect script

The code is as follows Copy Code

VI sshproxy.sh
#!/usr/bin/expect-f
Set Timeout 60
Spawn/usr/bin/ssh-qtfncngd 7070-g Username@serverip
Expect {
"Password:" {
Send "PASSWDR"
}
}
Interact {
Timeout {send "}
If [Fork]!=0 exit
Disconnect
}

chmod +x sshproxy.sh


3. Let the script run in the background

The code is as follows Copy Code
Nohup./sshproxy.sh


So here's what I've added to the script because of the expect relationship:

The code is as follows Copy Code
If [Fork]!=0 exit
Disconnect

So that its script can be executed in the background, if not, use nohup not to make the script execute, why not in the back of the script to add & reasons is the same reason.


4. Verify that the script has been successful

The code is as follows Copy Code
PS Aux|grep SSH
/usr/bin/ssh-qtfncngd 7070-g Username@serverip

If you see a process with an SSH agent in the process, it means that the execution of the script is successful, if not, then I suggest that you execute the script manually to see where the error is.

Two other options added

Scenario One: setting on the client

The method is simple, simply edit (requires root permission)/etc/ssh/ssh_config on the client computer and add the following line:
Serveraliveinterval 60
After that the user in this system connects ssh, every 60 seconds will send a keepalive request, avoids being kicked.

Scenario two: Setting on the server side

If you have the appropriate permissions, you can also set the server-side, edit/etc/ssh/sshd_config, and add:
Clientaliveinterval
After you restart the SSH server, the setting takes effect. Each client connected to this server will be affected by it

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.