使用SSH遇到ssh_exchange_identification错误

关键错误信息

ssh_exchange_identification: read: Operation timed out
debug1: key_load_public: No such file or directory

详细错误信息

$ ssh -T -vvv git@github.com
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/yuzefeng/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/yuzefeng/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
ssh_exchange_identification: read: Operation timed out

原因

在处理限制close_wait的时候错误的设置了系统socket参数,设置过小导致ssh操作超时。

解决方法

设置为适当的参数即可。

# mac os
sysctl net.inet.tcp | grep -E "keepidle|keepintvl|keepcnt"

sysctl -w net.inet.tcp.keepidle=180000 
sysctl -w net.inet.tcp.keepcnt=3 
sysctl -w net.inet.tcp.keepintvl=10000
    原文作者:余泽锋
    原文地址: https://zhuanlan.zhihu.com/p/45533147
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞