설치된 서버에 ssh 접속을 할 때 다음과 같은 에러가 발생
1 2 |
[root@master ssh]# ssh 192.168.1.100 Read from socket failed: Connection reset by peer |
해당 서버의 /var/log/message 로그를 보면 데몬 기동과 함께 키가 없다는 메세지와 외부에서 접속시 키값을 불러올 수 없다는 메세지를 확인할 수 있다.
1 2 3 4 5 6 7 8 9 10 |
Aug 24 09:46:23 localhost systemd: Stopping OpenSSH server daemon... Aug 24 09:46:23 localhost systemd: Started OpenSSH Server Key Generation. Aug 24 09:46:23 localhost systemd: Started OpenSSH server daemon. Aug 24 09:46:23 localhost systemd: Starting OpenSSH server daemon... Aug 24 09:46:23 localhost sshd: Could not load host key: /etc/ssh/ssh_host_rsa_key Aug 24 09:46:23 localhost sshd: Could not load host key: /etc/ssh/ssh_host_ecdsa_key Aug 24 09:46:23 localhost sshd: Could not load host key: /etc/ssh/ssh_host_ed25519_key Aug 24 09:59:10 localhost sshd[4875]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key Aug 24 09:59:10 localhost sshd[4875]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key Aug 24 09:59:10 localhost sshd[4875]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key |
ssh 관련 설정이 들어 있는 폴더 내용을 확인을 하니 접속을 위한 키 값이 생성이 되지 않았다.
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@localhost ~]# ls -l /etc/ssh total 252 -rw-r--r--. 1 root root 242153 Mar 22 07:18 moduli -rw-r--r--. 1 root root 2208 Mar 22 07:18 ssh_config -rw-------. 1 root root 4361 Mar 22 07:18 sshd_config -rw-r-----. 1 root ssh_keys 0 Aug 22 16:32 ssh_host_ecdsa_key -rw-r--r--. 1 root root 0 Aug 22 16:32 ssh_host_ecdsa_key.pub -rw-r-----. 1 root ssh_keys 0 Aug 22 16:32 ssh_host_ed25519_key -rw-r--r--. 1 root root 0 Aug 22 16:32 ssh_host_ed25519_key.pub -rw-r-----. 1 root ssh_keys 0 Aug 22 16:32 ssh_host_rsa_key -rw-r--r--. 1 root root 0 Aug 22 16:32 ssh_host_rsa_key.pub [root@localhost ~]# |
ssh 접속을 위해서 rsa, ecdsa, ed25519 키 값을 생성해 준다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
[root@localhost ~]# ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N "" Generating public/private rsa key pair. /etc/ssh/ssh_host_rsa_key already exists. Overwrite (y/n)? y Your identification has been saved in /etc/ssh/ssh_host_rsa_key. Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub. The key fingerprint is: c9:a4:ab:39:d3:17:79:f1:2a:d5:14:fb:8a:0a:2d:7a root@localhost.localdomain The key's randomart image is: +--[ RSA 2048]----+ | | | . | | . o | | + .. o | | . S. = . | | oo o o . | | .+ .+ o . | | o+Eoo o . | | ++ ..o | +-----------------+ [root@localhost ~]# ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -t ecdsa -N "" Generating public/private ecdsa key pair. /etc/ssh/ssh_host_ecdsa_key already exists. Overwrite (y/n)? y Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key. Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub. The key fingerprint is: 98:9b:9a:33:c1:bb:51:9b:bb:a3:ec:51:46:0f:2a:88 root@localhost.localdomain The key's randomart image is: +--[ECDSA 256]---+ | | | | | o | |.. o = | |E ... * S | | .o+ = | | oo= | | .+=.. | | .B=oo | +-----------------+ [root@localhost ~]# ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -t ed25519 -N "" Generating public/private ed25519 key pair. /etc/ssh/ssh_host_ed25519_key already exists. Overwrite (y/n)? y Your identification has been saved in /etc/ssh/ssh_host_ed25519_key. Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub. The key fingerprint is: 6e:80:ab:be:b8:09:a4:47:6b:23:16:c3:2f:2a:12:4e root@localhost.localdomain The key's randomart image is: +--[ED25519 256--+ | | | | | | |. . | | =. . . S | |+E+. . o | |*+=.. o | |*B.o . | |Bo+. | +-----------------+ [root@localhost ~]# |
문제 없이 ssh 연결이 되는 것을 확인할 수 있다.
1 2 3 4 5 6 7 8 |
[root@centos7 ssh]# ssh 192.168.1.100 The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established. ECDSA key fingerprint is 49:60:b6:36:91:f2:d2:f5:cd:4d:97:95:4c:e7:ec:d4. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.100' (ECDSA) to the list of known hosts. root@192.168.1.100's password: Last login: Wed Aug 24 09:46:09 2016 [root@localhost ~]# |