이런 일이 발생하는 이유: [내 호스트 IP] 포트 22에 의해 연결이 종료되었습니다.

이런 일이 발생하는 이유: [내 호스트 IP] 포트 22에 의해 연결이 종료되었습니다.

이것은 Buster를 실행하는 Pi 4에서 수행되었습니다.

이 Pi에서 웹 호스트(HostGator)로 SSH를 시도하고 있습니다.

RSA 키 쌍을 사용하여 Mac에서 HostGator로 SSH를 연결할 수 있기 때문에 호스트에서 SSH가 실행되고 있다는 것을 알고 있습니다. 비밀번호는 필요하지 않습니다.

MrMuscle:~ mnewman$ ssh mgnewman@[my host]
Last login: Sat Aug 22 17:47:47 2020 from 1.20.171.54
mgnewman@[my host] [~]#

비밀번호 없이 Mac에 SSH로 연결할 수 있기 때문에 SSH가 Pi에서 작동한다는 것을 알고 있습니다.

pi@raspsky:~/.ssh $ ssh [email protected]
Last login: Sun Aug 23 06:11:14 2020 from 192.168.0.65.
MrMuscle:~ mnewman$

호스트는 Known_hosts 파일에 있습니다.

pi@raspsky:~/.ssh $ ssh-keygen -F [my host]
# Host mgnewman.com found: line 1

이 Pi의 SD 카드는 다른 Pi 4에서 복제되었습니다. 새로운 Pi에서 새로운 공개/개인 키와 새로운 Authorized_keys 및 Known_hosts 파일을 생성했습니다.

내가 어떻게 작동하게 할 수 있는지 아는 사람이 있나요?

간단히 말해서:

pi@raspsky:~/.ssh $ ssh mgnewman@[my host]
Connection closed by [my host IP] port 22

공개 키가 호스트로 전송되면 Pi의 디버그 출력은 다음과 같습니다.

debug1: Offering public key: id_rsa RSA SHA256:4fUCtJQoMfxO/Za1goxtEjx5fyFq0tHgkus4jIhI7dE explicit
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
Connection closed by [myhost IP] port 22

다음은 Mac의 디버그 출력과 동일한 줄입니다.

debug1: Offering public key: /Users/mnewman/.ssh/id_rsa RSA SHA256:2RluaUDGj/vNTMBi9DD1nEHT/Ets+qwbdvo+E7DsKS0
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /Users/mnewman/.ssh/id_rsa RSA SHA256:2RluaUDGj/vNTMBi9DD1nEHT/Ets+qwbdvo+E7DsKS0
debug1: Authentication succeeded (publickey).
Authenticated to [myhost] ([my host IP]:22).
debug1: channel 0: new [client-session]

전체 자세한 출력은 다음과 같습니다.

pi@raspsky:~/.ssh $ ssh -vvv mgnewman@[my host]
OpenSSH_7.9p1 Raspbian-10+deb10u2, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "[my host]" port 22
debug2: ssh_connect_direct
debug1: Connecting to [my host] [[my host IP]] port 22.
debug1: Connection established.
debug1: identity file /home/pi/.ssh/id_rsa type 0
debug1: identity file /home/pi/.ssh/id_rsa-cert type -1
debug1: identity file /home/pi/.ssh/id_dsa type -1
debug1: identity file /home/pi/.ssh/id_dsa-cert type -1
debug1: identity file /home/pi/.ssh/id_ecdsa type -1
debug1: identity file /home/pi/[my host].ssh/id_ecdsa-cert type -1
debug1: identity file /home/pi/.ssh/id_ed25519 type -1
debug1: identity file /home/pi/.ssh/id_ed25519-cert type -1
debug1: identity file /home/pi/.ssh/id_xmss type -1
debug1: identity file /home/pi/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9p1 Raspbian-10+deb10u2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to [my host]:22 as 'mgnewman'
debug3: hostkeys_foreach: reading file "/home/pi/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/pi/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [my host]
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa
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,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-```
debug2: host key algorithms: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa,[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
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: diffie-hellman-group-exchange-sha256
debug2: host key algorithms: ssh-rsa,ssh-dss
debug2: ciphers ctos: aes256-ctr,aes192-ctr,aes128-ctr
debug2: ciphers stoc: aes256-ctr,aes192-ctr,aes128-ctr
debug2: MACs ctos: hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected]
debug2: MACs stoc: hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected]
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: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug3: send packet: type 34
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<8192<8192) sent
debug3: receive packet: type 31
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 4114/8192
debug3: send packet: type 32
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug3: receive packet: type 33
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:zvfdYBMDWtOFnGjLosCOjO9MNKNaLHVcYNJSg6Wx428
debug3: hostkeys_foreach: reading file "/home/pi/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/pi/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from [my host]
debug3: hostkeys_foreach: reading file "/home/pi/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/pi/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys from [my host IP]
debug1: Host '[my host]' is known and matches the RSA host key.
debug1: Found key in /home/pi/.ssh/known_hosts:1
debug2: bits set: 4034/8192
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug1: Will attempt key: /home/pi/.ssh/id_rsa RSA SHA256:4fUCtJQoMfxO/Za1goxtEjx5fyFq0tHgkus4jIhI7dE
debug1: Will attempt key: /home/pi/.ssh/id_dsa
debug1: Will attempt key: /home/pi/.ssh/id_ecdsa
debug1: Will attempt key: /home/pi/.ssh/id_ed25519
debug1: Will attempt key: /home/pi/.ssh/id_xmss
debug2: pubkey_prepare: done
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,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,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 public key: /home/pi/.ssh/id_rsa RSA SHA256:4fUCtJQoMfxO/Za1goxtEjx5fyFq0tHgkus4jIhI7dE
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
Connection closed by [my host IP] port 22

답변1

여기서 무슨 일이 일어나고 있는지 잘 모르겠습니다. rsa를 작동시킬 수 없어서 ecdsa를 시도해 볼까 생각했습니다. 키 쌍을 생성하고 공개 ecdsa 키를 호스트의authorized_keys 파일에 복사했습니다. SSH를 사용하여 연결을 시도했는데 작동했습니다.

pi@raspsky:~/.ssh $ ssh -i /home/pi/.ssh/id_ecdsa mgnewman@[myhost].com
Last login: Sun Aug 23 23:53:26 2020 from 1.20.171.54
mgnewman@[myhost].com [~]# exit

그런 다음 rsa를 다시 시도했습니다. 그것도 작동했습니다.

ecdsa 키를 붙여넣을 때 Authorized_keys 파일을 어떻게든 "수정"했습니까? 아마도.

관련 정보