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

2016-12-10 23:17:04 +08:00
 bjlbeyond
在公司用 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

求计策
7804 次点击
所在节点    程序员
26 条回复
aec4d
2016-12-11 00:44:12 +08:00
-vvv 贴出来
ibigbug
2016-12-11 01:23:51 +08:00
Write failed: Broken pipe 这不是已经连上了么?延迟太大了吧。
xiuc001
2016-12-11 01:29:01 +08:00
服务器限制了 ip 地址吧,只有公司的 ip 地址可以连,你在家里 ip 和公司不一样的
xiuc001
2016-12-11 01:31:22 +08:00
如果工作需要就找运维,如果不想麻烦运维,那么把电脑放在公司,然后在这个电脑上开一个 ngrok ,你就可以通过 ngrok 连接公司的那台电脑,然后再通过公司那台电脑就可以连公司的服务器了= =
sagaxu
2016-12-11 09:07:00 +08:00
是不是配了代理或者 vpn?
icegreen
2016-12-11 09:30:01 +08:00
应该是限制了 ip.
bjlbeyond
2016-12-11 09:41:30 +08:00
@icegreen 我在家用这个电脑的里的虚拟机是可以连上公司服务器的,而且用另外的 windows 电脑也可以连上
bjlbeyond
2016-12-11 09:55:04 +08:00
@aec4d 怎么用?求指教
bjlbeyond
2016-12-11 09:55:20 +08:00
@sagaxu 没有
bjlbeyond
2016-12-11 09:55:55 +08:00
@xiuc001 没有限制 ip ,在家里另外一台电脑就可以连接上去
aec4d
2016-12-11 09:57:41 +08:00
ssh xxx -vvv 看全部的日志 是什么问题自然一清二楚
bjlbeyond
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: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,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: curve25519-sha256@libssh.org,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: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256@libssh.org,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,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: MACs ctos: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: MACs stoc: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com 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
2016-12-11 10:15:26 +08:00
root@101.200.63.184'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 no-more-sessions@openssh.com
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
2016-12-11 10:24:43 +08:00
@bjlbeyond 记得把日志中的 ip 去掉啊,另外 root 用户+密码登陆??
日志没看出来什么有用的东西,建议你去看看服务器日志
shiji
2016-12-11 10:25:01 +08:00
@Livid 是不是要帮这位隐藏一下服务器 IP.. 不经意之间就粘贴出来了。。
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
2016-12-11 10:36:21 +08:00
忽略我上面说的代理 直接测试 ProxyCommand /usr/bin/nc %h %p
kkk330
2016-12-11 10:48:25 +08:00
iterm2 不走代理的
bjlbeyond
2016-12-11 10:49:37 +08:00
@des
@shiji 不经意间给粘贴出来了,汗。。。
bjlbeyond
2016-12-12 16:52:23 +08:00
求解决办法啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/326741

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX