请教个 ssh 连接的问题,被折麽够呛 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
bjlbeyond
V2EX    程序员

请教个 ssh 连接的问题,被折麽够呛

  •  
  •   bjlbeyond 2016-12-10 23:17:04 +08:00 8186 次点击
    这是一个创建于 3229 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在公司用 mac 可以 ssh 连接上服务器,具体的配置都放在 config 文件中,目录和格式都正确。因为在公司确实连接上了。用 iterm 和 zoc 都可以连接上!

    但把这个电脑带回家死活就是连接不上服务器,报 Operation timed out 、 Write failed: Broken pipe 。


    尝试的方法:
    1 、网上找此问题解决办法全是清一色的说在 config 文件中加上这些配置 ServerAliveInterval 120
    TCPKeepAlive yes 都试了并且不管用。
    2 、可我在电脑上启动虚拟机在 window 的环境下可以连接上公司的这台服务器的,证明网络是没有问题的。并且尝试连手机的 4g 网、无果
    3 、在家 ping 不通公司的服务器
    4 、公司服务器是没有问题的,因为同样连接不上我的阿里云服务器 ecs

    求计策
    26 条回复    2016-12-12 17:48:17 +08:00
    aec4d
        1
    aec4d  
       2016-12-11 00:44:12 +08:00 via iPhone
    -vvv 贴出来
    ibigbug
        2
    ibigbug  
       2016-12-11 01:23:51 +08:00
    Write failed: Broken pipe 这不是已经连上了么?延迟太大了吧。
    xiuc001
        3
    xiuc001  
       2016-12-11 01:29:01 +08:00
    服务器限制了 ip 地址吧,只有公司的 ip 地址可以连,你在家里 ip 和公司不一样的
    xiuc001
        4
    xiuc001  
       2016-12-11 01:31:22 +08:00
    如果工作需要就找运维,如果不想麻烦运维,那么把电脑放在公司,然后在这个电脑上开一个 ngrok ,你就可以通过 ngrok 连接公司的那台电脑,然后再通过公司那台电脑就可以连公司的服务器了= =
    sagaxu
        5
    sagaxu  
       2016-12-11 09:07:00 +08:00
    是不是配了代理或者 vpn?
    icegreen
        6
    icegreen  
       2016-12-11 09:30:01 +08:00
    应该是限制了 ip.
    bjlbeyond
        7
    bjlbeyond  
    OP
       2016-12-11 09:41:30 +08:00 via iPhone
    @icegreen 我在家用这个电脑的里的虚拟机是可以连上公司服务器的,而且用另外的 windows 电脑也可以连上
    bjlbeyond
        8
    bjlbeyond  
    OP
       2016-12-11 09:55:04 +08:00
    @aec4d 怎么用?求指教
    bjlbeyond
        9
    bjlbeyond  
    OP
       2016-12-11 09:55:20 +08:00
    @sagaxu 没有
    bjlbeyond
        10
    bjlbeyond  
    OP
       2016-12-11 09:55:55 +08:00
    @xiuc001 没有限制 ip ,在家里另外一台电脑就可以连接上去
    aec4d
        11
    aec4d  
       2016-12-11 09:57:41 +08:00
    ssh xxx -vvv 看全部的日志 是什么问题自然一清二楚
    bjlbeyond
        12
    bjlbeyond  
    OP
       2016-12-11 10:15:07 +08:00
    @aec4d 打印出来很多、显示密码认证已经成功了,但是不知道为啥连不上
    OpenSSH_7.2p2, LibreSSL 2.4.1
    debug1: Reading configuration data /Users/bjlbeyond/.ssh/config
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 20: Applying options for *
    debug2: resolving "101.200.63.184" port 22
    debug2: ssh_connect_direct: needpriv 0
    debug1: Connecting to 101.200.63.184 [101.200.63.184] port 22.
    debug1: Connection established.
    debug1: identity file /Users/bjlbeyond/.ssh/id_rsa type 1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_ecdsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_ecdsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_ed25519 type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/bjlbeyond/.ssh/id_ed25519-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_7.2
    debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
    debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
    debug2: fd 3 setting O_NONBLOCK
    debug1: Authenticating to 101.200.63.184:22 as 'root'
    debug3: hostkeys_foreach: reading file "/Users/bjlbeyond/.ssh/known_hosts"
    debug3: record_hostkey: found key type ECDSA in file /Users/bjlbeyond/.ssh/known_hosts:21
    debug3: load_hostkeys: loaded 1 keys from 101.200.63.184
    debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
    debug3: send packet: type 20
    debug1: SSH2_MSG_KEXINIT sent
    debug3: receive packet: type 20
    debug1: SSH2_MSG_KEXINIT received
    debug2: local client KEXINIT proposal
    debug2: KEX algorithms: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-c
    debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
    debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
    debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
    debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
    debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
    debug2: compression ctos: none,[email protected],zlib
    debug2: compression stoc: none,[email protected],zlib
    debug2: languages ctos:
    debug2: languages stoc:
    debug2: first_kex_follows 0
    debug2: reserved 0
    debug2: peer server KEXINIT proposal
    debug2: KEX algorithms: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2: host key algorithms: ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
    debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
    debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
    debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
    debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
    debug2: compression ctos: none,[email protected]
    debug2: compression stoc: none,[email protected]
    debug2: languages ctos:
    debug2: languages stoc:
    debug2: first_kex_follows 0
    debug2: reserved 0
    debug1: kex: algorithm: [email protected]
    debug1: kex: host key algorithm: ecdsa-sha2-nistp256
    debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
    debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
    debug3: send packet: type 30
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug3: receive packet: type 31
    debug1: Server host key: ecdsa-sha2-nistp256 SHA256:zhKCIsZhxq5sDg73S6rVQ6AAYEU1KKkkJQfoi30n5Cg
    debug3: hostkeys_foreach: reading file "/Users/bjlbeyond/.ssh/known_hosts"
    debug3: record_hostkey: found key type ECDSA in file /Users/bjlbeyond/.ssh/known_hosts:21
    debug3: load_hostkeys: loaded 1 keys from 101.200.63.184
    debug1: Host '101.200.63.184' is known and matches the ECDSA host key.
    debug1: Found key in /Users/bjlbeyond/.ssh/known_hosts:21
    debug3: send packet: type 21
    debug2: set_newkeys: mode 1
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug3: receive packet: type 21
    debug2: set_newkeys: mode 0
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS received
    debug2: key: /Users/bjlbeyond/.ssh/id_rsa (0x7fb9cac13760)
    debug2: key: /Users/bjlbeyond/.ssh/id_dsa (0x0)
    debug2: key: /Users/bjlbeyond/.ssh/id_ecdsa (0x0)
    debug2: key: /Users/bjlbeyond/.ssh/id_ed25519 (0x0)
    debug3: send packet: type 5
    debug3: receive packet: type 6
    debug2: service_accept: ssh-userauth
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug3: send packet: type 50
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
    debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
    debug3: preferred publickey,keyboard-interactive,password
    debug3: authmethod_lookup publickey
    debug3: remaining preferred: keyboard-interactive,password
    debug3: authmethod_is_enabled publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/bjlbeyond/.ssh/id_rsa
    debug3: send_pubkey_test
    debug3: send packet: type 50
    debug2: we sent a publickey packet, wait for reply
    debug3: receive packet: type 51
    debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
    debug1: Trying private key: /Users/bjlbeyond/.ssh/id_dsa
    debug3: no such identity: /Users/bjlbeyond/.ssh/id_dsa: No such file or directory
    debug1: Trying private key: /Users/bjlbeyond/.ssh/id_ecdsa
    debug3: no such identity: /Users/bjlbeyond/.ssh/id_ecdsa: No such file or directory
    debug1: Trying private key: /Users/bjlbeyond/.ssh/id_ed25519
    debug3: no such identity: /Users/bjlbeyond/.ssh/id_ed25519: No such file or directory
    debug2: we did not send a packet, disable method
    debug3: authmethod_lookup password
    debug3: remaining preferred: ,password
    debug3: authmethod_is_enabled password
    debug1: Next authentication method: password
    bjlbeyond
        13
    bjlbeyond  
    OP
       2016-12-11 10:15:26 +08:00
    [email protected]'s password:
    debug3: send packet: type 50
    debug2: we sent a password packet, wait for reply
    debug3: receive packet: type 52
    debug1: Authentication succeeded (password).
    Authenticated to 101.200.63.184 ([101.200.63.184]:22).
    debug1: channel 0: new [client-session]
    debug3: ssh_session2_open: channel_new: 0
    debug2: channel 0: send open
    debug3: send packet: type 90
    debug1: Requesting [email protected]
    debug3: send packet: type 80
    debug1: Entering interactive session.
    debug1: pledge: network
    debug3: receive packet: type 91
    debug2: callback start
    debug2: fd 3 setting TCP_NODELAY
    debug3: ssh_packet_set_tos: set IP_TOS 0x10
    debug2: client_session2_setup: id 0
    debug2: channel 0: request pty-req confirm 1
    debug3: send packet: type 98
    debug1: Sending environment.
    debug3: Ignored env TERM_SESSION_ID
    debug3: Ignored env SSH_AUTH_SOCK
    debug3: Ignored env Apple_PubSub_Socket_Render
    debug3: Ignored env COLORFGBG
    debug3: Ignored env ITERM_PROFILE
    debug3: Ignored env XPC_FLAGS
    debug1: Sending env LANG = zh_CN.UTF-8
    debug2: channel 0: request env confirm 0
    debug3: send packet: type 98
    debug3: Ignored env PWD
    debug3: Ignored env SHELL
    debug3: Ignored env TERM_PROGRAM_VERSION
    debug3: Ignored env TERM_PROGRAM
    debug3: Ignored env PATH
    debug3: Ignored env TERM
    debug3: Ignored env HOME
    debug3: Ignored env TMPDIR
    debug3: Ignored env USER
    debug3: Ignored env XPC_SERVICE_NAME
    debug3: Ignored env LOGNAME
    debug3: Ignored env ITERM_SESSION_ID
    debug3: Ignored env __CF_USER_TEXT_ENCODING
    debug3: Ignored env SHLVL
    debug3: Ignored env OLDPWD
    debug3: Ignored env ZSH
    debug3: Ignored env PAGER
    debug3: Ignored env LESS
    debug1: Sending env LC_CTYPE = zh_CN.UTF-8
    debug2: channel 0: request env confirm 0
    debug3: send packet: type 98
    debug3: Ignored env LSCOLORS
    debug3: Ignored env MAVEN_HOME
    debug3: Ignored env JAVA_HOME
    debug3: Ignored env CLASSPATH
    debug3: Ignored env _
    debug2: channel 0: request shell confirm 1
    debug3: send packet: type 98
    debug2: callback done
    debug2: channel 0: open confirm rwindow 0 rmax 32768
    debug3: send packet: type 1
    packet_write_wait: Connection to 101.200.63.184 port 22: Broken pipe
    des
        14
    des  
       2016-12-11 10:24:43 +08:00
    @bjlbeyond 记得把日志中的 ip 去掉啊,另外 root 用户+密码登陆??
    日志没看出来什么有用的东西,建议你去看看服务器日志
    shiji
        15
    shiji  
       2016-12-11 10:25:01 +08:00
    @Livid 是不是要帮这位隐藏一下服务器 IP.. 不经意之间就粘贴出来了。。
    aec4d
        16
    aec4d  
       2016-12-11 10:28:43 +08:00
    http://serverfault.com/questions/692026/cant-complete-ssh-connection-after-successfully-exchanging-keys-to-ubuntu-from

    看起来很复杂啊...你可以试试按照上面的做法,设置通过代理连接看看 比如你本机开了一个 1080 的端口是 socks5 代理,试一下配置添加 ProxyCommand /usr/bin/nc -X 5 -x localhost:1080 %h %p
    aec4d
        17
    aec4d  
       2016-12-11 10:36:21 +08:00
    忽略我上面说的代理 直接测试 ProxyCommand /usr/bin/nc %h %p
    kkk330
        18
    kkk330  
       2016-12-11 10:48:25 +08:00 via Android
    iterm2 不走代理的
    bjlbeyond
        19
    bjlbeyond  
    OP
       2016-12-11 10:49:37 +08:00
    @des
    @shiji 不经意间给粘贴出来了,汗。。。
    bjlbeyond
        20
    bjlbeyond  
    OP
       2016-12-12 16:52:23 +08:00
    求解决办法啊
    nightYe
        21
    nightYe  
       2016-12-12 17:26:08 +08:00
    公司局域网 ip 在服务器上设置白名单了吧
    bjlbeyond
        22
    bjlbeyond  
    OP
       2016-12-12 17:28:48 +08:00
    @nightYe 我回家后用其他电脑是可以连接上的,而且我同样用 mac 连不上自己的阿里云服务器
    nightYe
        23
    nightYe  
       2016-12-12 17:30:45 +08:00
    @bjlbeyond 你 windows 能连上吗,用什么工具连的
    bjlbeyond
        24
    bjlbeyond  
    OP
       2016-12-12 17:37:27 +08:00
    @nightYe xshell
    nightYe
        25
    nightYe  
       2016-12-12 17:44:22 +08:00
    @bjlbeyond 有尝试过清理 mac 上的 ssh key 吗,以前有遇到过类似的这种现象,不过当时是服务器重装造成的,清除本地的 ssh key 缓存重新连接即可。你可以尝试一下。
    bjlbeyond
        26
    bjlbeyond  
    OP
       2016-12-12 17:48:17 +08:00
    @nightYe 自从买回这个电脑,在家就没连成功过公司的电脑,在公司这台电脑能正常连接
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     967 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 22:37 PVG 06:37 LAX 15:37 JFK 18:37
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86