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