Linux

SCP 有效,但 SSH 無效(通過 wifi)

  • December 20, 2018

當我在辦公室使用 wifi 時,我可以使用 SCP 將文件複製到我的伺服器或從我的伺服器複製文件,但由於某種原因 SSH 沒有響應。它只是掛起,不列印任何東西,而且我無法ctrl-c結束它;我必須關閉終端視窗。

當我接入區域網路時,一切正常。任何想法如何弄清楚發生了什麼?

我終於找到了導致問題的原因。這是由於我的路由器在我無線連接時阻止了 TCP keepalive 消息(見圖)。

ssh my_server -o TCPKeepAlive=no解決了我所有的問題。耶!

從文件中:

TCPKeepAlive
 Specifies whether the system should send TCP keepalive messages
 to the other side. If they are sent, death of the connection or
 crash of one of the machines will be properly noticed.  However,
 this means that connections will die if the route is down tem-
 porarily, and some people find it annoying.  On the other hand,
 if TCP keepalives are not sent, sessions may hang indefinitely on
 the server, leaving "ghost" users and consuming server resources.

 The default is "yes" (to send TCP keepalive messages), and the
 server will notice if the network goes down or the client host
 crashes.  This avoids infinitely hanging sessions.

 To disable TCP keepalive messages, the value should be set to
 "no".

引用自:https://unix.stackexchange.com/questions/22929