우분투에서 ssh 접속이 거부 당한다면

우분투의 open-ssh 패키지의 기본 설정을 가지고 외부 ssh 서버에 접속할 경우 항상 커넥션이 리셋되어 회사 방화벽에서 포트를 막았겠거니 하면서 지냈습니다.

Read from socket failed: Connection reset by peer

그렇게 지내다 업무를 위해 사용할 필요가 생겨 SE팀에 문의를 하니 포트는 막지 않고 있다고 하니 이게 무슨 문제인가 하고 debug 모드로 접속을 해보았습니다. 연결이 이루어지고 인증을 하는 과정에서 문제가 있던 것입니다.

debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2

debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*

debug1: Enabling compatibility mode for protocol 2.0

debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1

debug1: SSH2_MSG_KEXINIT sent

Read from socket failed: Connection reset by peer

열심히 뒤진 끝에 힌트를 잡았습니다.

ssh client problem: Connection reset by peer

  • Limit cipher list length by using ‘-c ’ in the ssh command line, e.g. ‘-c aes256-ctr’
  • Limit HostKeyAlgorithms list by adding to ~/.ssh/config:

직접 해보니 HostKeyAlgorithms 옵션의 문제입니다. 가르침에 따라 옵션의 주석을 풀고 알고리즘을 모두 추가해 놓았습니다.

HostKeyAlgorithms ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,ssh-dss

debug1: SSH2_MSG_KEXINIT sent

debug1: SSH2_MSG_KEXINIT received

debug1: kex: server->client aes128-ctr hmac-md5 none

debug1: kex: client->server aes128-ctr hmac-md5 none

debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent

debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP

debug1: SSH2_MSG_KEX_DH_GEX_INIT sent

debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY

히로꾸나 gihub 모두 문제 없이 연결이 됩니다.