![SSH 공개 키 인증 실패: 패킷 수신: 유형 51. sshd는 공개 키 인증을 전혀 허용하지 않습니다](https://linux55.com/image/208015/SSH%20%EA%B3%B5%EA%B0%9C%20%ED%82%A4%20%EC%9D%B8%EC%A6%9D%20%EC%8B%A4%ED%8C%A8%3A%20%ED%8C%A8%ED%82%B7%20%EC%88%98%EC%8B%A0%3A%20%EC%9C%A0%ED%98%95%2051.%20sshd%EB%8A%94%20%EA%B3%B5%EA%B0%9C%20%ED%82%A4%20%EC%9D%B8%EC%A6%9D%EC%9D%84%20%EC%A0%84%ED%98%80%20%ED%97%88%EC%9A%A9%ED%95%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4.png)
나는 이 문제에 대한 많은 해결책을 읽었지만 내가 보고 있는 것과는 어떤 것도 효과가 없는 것 같습니다. 대부분은 디렉터리 권한에 중점을 두지만 이 경우에는 이것이 올바른 것 같습니다. 핵심요약: 동일한 홈 디렉터리를 가진 두 개의 Centos7 서버; sshd
활성화된 경우에도 공개 키 인증이 허용되지 않습니다.
두 개의 centos7 서버가 있습니다 . centos-a
이를 . centos-b
홈 디렉토리는 NFS를 통해 마운트되므로 .ssh
둘 사이의 디렉토리는 동일합니다(아래에서 확인하세요). centos-a
에서 로 SSH를 통해 연결할 수 있지만 centos-a
에서는 ssh로 연결할 수 없습니다 centos-b
. 에서 SSH를 통해 centos-b
이동할 수 있습니다 .centos-a
centos-b
SSH 기능 | centos-a |
centos-b |
---|---|---|
centos-a |
예 | 아니요 |
centos-b |
예 | 예 |
[myuser@centos-a ~]$ ls -la ~/.ssh
total 16
drwx------. 1 myuser domain users 0 Jul 6 11:45 .
drwx------. 1 myuser domain users 0 Jul 7 13:44 ..
-rw-------. 1 myuser domain users 1212 Jul 6 12:02 authorized_keys
-rw-------. 1 myuser domain users 1675 Jul 6 11:45 id_rsa
-rw-r--r--. 1 myuser domain users 402 Jul 6 11:45 id_rsa.pub
-rw-r--r--. 1 myuser domain users 1119 Jul 6 17:49 known_hosts
[myuser@centos-a ~]$ md5sum ~/.ssh/*
65b4fdf2d59cee3ae45b8480454453ec /home/myuser/.ssh/authorized_keys
fa3e9fc5a8ff08787ff2ba8f979da24e /home/myuser/.ssh/id_rsa
dca36ab3ec342423c5eca588f2ad5678 /home/myuser/.ssh/id_rsa.pub
f67bc94bc7a30b9876e3027b24f893d8 /home/myuser/.ssh/known_hosts
[myuser@centos-a ~]$ ssh centos-a hostname
centos-a
[myuser@centos-a ~]$ ssh centos-b hostname
myuser@centos-b's password:
[myuser@centos-b ~]$ ls -la ~/.ssh
total 16
drwx------. 1 myser domain users 0 Jul 6 11:45 .
drwx------. 1 myser domain users 0 Jul 7 13:44 ..
-rw-------. 1 myser domain users 1212 Jul 6 12:02 authorized_keys
-rw-------. 1 myser domain users 1675 Jul 6 11:45 id_rsa
-rw-r--r--. 1 myser domain users 402 Jul 6 11:45 id_rsa.pub
-rw-r--r--. 1 myser domain users 1119 Jul 6 17:49 known_hosts
[myuser@centos-b ~]$ md5sum ~/.ssh/*
65b4fdf2d59cee3ae45b8480454453ec /home/myuser/.ssh/authorized_keys
fa3e9fc5a8ff08787ff2ba8f979da24e /home/myuser/.ssh/id_rsa
dca36ab3ec342423c5eca588f2ad5678 /home/myuser/.ssh/id_rsa.pub
f67bc94bc7a30b9876e3027b24f893d8 /home/myuser/.ssh/known_hosts
[myuser@centos-b ~]$ ssh centos-b hostname
centos-b
[myuser@centos-b ~]$ ssh centos-a hostname
centos-a
위에 표시된 대로 .ssh 디렉토리에 대한 권한은 올바른 것으로 보입니다(그리고 어쨌든 두 시스템 간에 동일합니다).
ssh -vvv
실패한 SSH는 다음을 표시합니다.
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
...
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
...
debug1: Host 'centos-b' is known and matches the ECDSA host key.
...
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 gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1211402155)
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1211402155)
debug2: we did not send a packet, disable method
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: /home/myuser/.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: /home/myuser/.ssh/id_dsa
debug3: no such identity: /home/myuser/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/myuser/.ssh/id_ecdsa
debug3: no such identity: /home/myuser/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/myuser/.ssh/id_ed25519
debug3: no such identity: /home/myuser/.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
myuser@centos-b's password:
이것을 에서 본 것과 대조하면 다음과 같이 centos-b
작동 centos-a
합니다.
...
debug1: Unspecified GSS failure. Minor code may provide more information
Server not found in Kerberos database
debug3: send packet: type 50
debug2: we sent a gssapi-with-mic packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug2: we did not send a packet, disable method
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: /home/myuser/.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 60
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug2: input_userauth_pk_ok: fp SHA256:nAO5pVOzqUQzEUSEBN37WKp6ADs9Sk4rfTRGmk0FHEY
debug3: sign_and_send_pubkey: RSA SHA256:nAO5pVOzqUQzEUSEBN37WKp6ADs9Sk4rfTRGmk0FHEY
debug3: send packet: type 50
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).
SSHD 로그 메시지를 활성화 /etc/ssh/sshd_config
하고 서비스를 다시 시작했습니다.
# Logging
SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel INFO
/var/log/secure
하지만 어느 쪽에도 다른 유용한 소식은 없습니다 /var/log/messages
.
재미있게centos-b
SSH에서 centos-b
gssapi 인증을 사용합니다. 공개 키를 사용하도록 강제하면 실패합니다.
[myuser@centos-b ~]$ ssh -vvv -o PreferredAuthentications=publickey centos-b hostname
...
debug1: Offering RSA public key: /home/myuser/.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
...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
나는 보았다 /var/log/messages
:
Jul 7 13:52:10 centos-b sshd[23266]: Connection closed by 192.168.1.100 port 48064 [preauth]
공개 키 활성화됨:
[root@centos-b ssh]# sshd -T | grep -i pub
pubkeyauthentication yes
pubkeyacceptedkeytypes [email protected],ecdsa-sha...
이것은 sshd_config
재고 Centos7이며 sshd_config
및 사이에서 동일합니다(두 시스템에서 다음 명령을 파이핑하여 확인).centos-a
centos-b
md5sum
[root@centos-b ssh]# grep -v -e '^#' -e '^$' /etc/ssh/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
내가 놓친 것에 대한 제안이 있습니까?
답변1
.ssh
문제는 ID 디렉터리(어쩌면 그 이상)의 SELinux 컨텍스트와 관련이 있을 수 있습니다. 컨텍스트(in .ssh
)에 유형이 있는지 확인하세요 ssh_home_t
.
이는 SSH 사용자 파일에 필요한 권한과 유사합니다( rwx
그룹/기타에는 필요하지 않음). 확인하지는 않았지만 아마도 양쪽 끝에 필요할 것입니다( .ssh
소스 및 대상 사용자 디렉터리 모두 동일한 컨텍스트가 필요함).
다음은 "올바른" 컨텍스트의 예입니다.
[account@hostname .ssh]# ls -alZ
drwx------. account account unconfined_u:object_r:ssh_home_t:s0 .
drwx------. account account unconfined_u:object_r:user_home_dir_t:s0 ..
-rw-------. account account unconfined_u:object_r:ssh_home_t:s0 authorized_keys
-rw-------. account account unconfined_u:object_r:ssh_home_t:s0 id_rsa
-rw-------. account account unconfined_u:object_r:ssh_home_t:s0 id_rsa.pub
-rw-r--r--. account account unconfined_u:object_r:ssh_home_t:s0 known_hosts
답변2
추가 인터넷 검색을 통해 내가 구성한 새 시스템에서 SELinux를 활성화하는 데 문제가 있다고 말했습니다. 제 경우에는 허용으로 설정하면 문제가 해결되었습니다.
# getenforce
Enforcing
# setenforce 0
# getenforce
Permissive
이는 자신의 환경에 SELinux가 필요한 사람들에게는 적합한 솔루션이 아닐 수도 있습니다. 영구 변경에는 업데이트가 포함됩니다 /etc/selinux/config
.
답변3
글쎄요, 저는 새로 만든 데비안 12 서버에서 같은 일을 하면서 이 문제를 해결하는 데 5시간을 보냈습니다.
- .ssh 파일/폴더에 대한 권한 확인
- /etc/ssh/sshd_config 파일을 작업 호스트와 비교
sshd -T
출력을 작업 호스트와 비교- 출력 비교
ssh -vvv root@host 2>ssh.log
- 온라인 조사가 많음
결과적으로 이 특정 호스트에서 왜 이런 일이 발생하는지 아직 잘 모르겠습니다. 매달 수십 개의 VM에서 이 작업을 수행하지만 그렇게 하면 scp-copy-id root@host
기본 이외의 다른 목적으로 사용하는 대체 공개 키가 설치됩니다. 생각했던 데로~/.ssh/id_rsa.pub.
따라서 여기에 왔지만 아직 완료하지 않은 경우 대상의 ~/.ssh/authorized_keys를 클라이언트의 ~/.ssh/id_rsa.pub와 비교하십시오.
동일하지 않은 경우 대상 호스트의 Authorized_keys에서 잘못된 항목을 제거한 다음(또는 파일이 하나만 있는 경우 파일을 삭제) 명시적으로 가져와야 합니다.
ssh-copy-id -i ~/.ssh/id_rsa.pub root@host
내 빌드 루틴을 수정했고 이제 큰 마티니 몇 잔을 마시게 되었습니다...