问一个SSH的问题

上网、浏览、聊天、下载等
回复
flyonsnow
帖子: 2
注册时间: 2009-07-12 4:47

问一个SSH的问题

#1

帖子 flyonsnow » 2009-10-16 9:03

ssh连接远程主机的时候,如果一段时间不操作,ssh中断就会没有响应了。
不知道设置那些参数,能够是ssh终端始终于远程主机通信呢?
头像
冲浪板
论坛版主
帖子: 7513
注册时间: 2007-05-06 8:19

Re: 问一个SSH的问题

#2

帖子 冲浪板 » 2009-10-16 9:49

是有,找找看
头像
devin
帖子: 189
注册时间: 2008-08-26 22:57
来自: 长沙

Re: 问一个SSH的问题

#3

帖子 devin » 2009-10-16 12:49

转自: http://www.ilikeblog.com/user1/1/archiv ... /1392.html
自从用上ssh以来,就常常被它的自动断线所困扰。太烦了。。。今天实在受不了了,上网仔细查,找到一些。有人说在/etc/profile中设置TMOUT,有人说那样根本不行,因为ssh断线是因为防火墙的设置,当一定时间内没有tcp /ip流量,就会自动断开。当然这是有可能的。

从网上找到这个页面:http://madphilosopher.ca/2005/07/an-ssh-keep-alive-tip/

其中提到的几个方法不错:

一,使用screen。不管你有没有root权限,都可以利用screen,方法是 修改 ~/.screenrc,增加一行:caption always '%c:%s'。这个方法的效果很漂亮,而且有效。我的做法是把screen放在.bash_profile的最后一行。这样登陆后就直接在screen里了。

二,修改/etc/ssh/sshd_config,增加下面两行(本方法经测试应该是可行的)
KeepAlive yes
ClientAliveInterval 60

三,A friend of mine wrote this for me awhile back. He calls it spin.c
Compile this and run it… it’ll give you a nice spinny thing to keep your ssh session busy.

#i nclude <stdio.h>
int i;
char spin[4] = { '|', '/', '-', '\\' };
void main() {
for(i=0;;usleep(300000), fflush(stdout))
printf("%c\x08", spin[++i%4]);
}

四,修改$HOME/.ssh/config

ServerAliveInterval 60

五,修改putty的某个设置,可以保持不断线。网址见后,不过我没有帐户所以看不到。意思已经明白了。

http://www.jaguarpc.com/forums/showthread.php?p=101123

六,看了关于ServerAliveInterval的讨论(似乎只能在ssh3.8+上使用),我查过自己的redhat9的ssh文档(man sshd_config,发现有另外的办法似乎可行:


ClientAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the client, sshd 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.

ClientAliveCountMax
Sets the number of client alive messages (see above) which may be sent without sshd receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different from KeepAlive (below). The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by KeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become inactive.
i7 2630QM+ 4G ram + 500g hd + arch
11.04装新机器上死机,只好换arch了
回复