공개 키 인증은 sshd가 데몬 인 경우에만 실패합니다 attempt 2

나는 이것이 어떻게 일어나는지 전혀 모른다. 배포판은 Scientific Linux 6.1이며 공개 키를 통해 인증을 수행하도록 모든 것이 설정되었습니다. 그러나 sshd가 데몬 (서비스 sshd start)으로 실행 중이면 공개 키를 허용하지 않습니다. (이 로그 조각을 얻기 위해 -ddd 옵션을 추가하도록 sshd 스크립트를 변경했습니다)

debug1: trying public key file /root/.ssh/authorized_keys
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys2
debug1: restore_uid: 0/0
Failed publickey for root from xxx.xxx.xxx.xxx port xxxxx ssh2
debug3: mm_answer_keyallowed: key 0x7f266e1a8840 is not allowed
debug3: mm_request_send entering: type 22
debug3: mm_request_receive entering
debug2: userauth_pubkey: authenticated 0 pkalg ssh-rsa
debug3: Wrote 64 bytes for a total of 1853
debug1: userauth-request for user root service ssh-connection method publickey
debug1: attempt 2 failures 1

sshd가 디버그 모드에서 실행 /usr/sbin/sshd -ddd되면 인증은 매력처럼 작동합니다.

debug1: trying public key file /root/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: matching key found: file /root/.ssh/authorized_keys, line 1
Found matching RSA key: d7:3a:08:39:f7:28:dc:ea:f3:71:7c:23:92:02:02:d8
debug1: restore_uid: 0/0
debug3: mm_answer_keyallowed: key 0x7f85527ef230 is allowed
debug3: mm_request_send entering: type 22
debug3: mm_request_receive entering
debug3: Wrote 320 bytes for a total of 2109
debug2: userauth_pubkey: authenticated 0 pkalg ssh-rsa
Postponed publickey for root from xxx.xxx.xxx.xxx port xxxxx ssh2
debug1: userauth-request for user root service ssh-connection method publickey
debug1: attempt 2 failures 0

어떤 아이디어 ?? 누구든지 이런 것을 본 적이 있습니까?

노트:

파일 권한이 두 번 확인되었습니다.

# ll -d .ssh
drwx------. 2 root root 4096 Oct 14 10:05 .ssh
# ll .ssh
total 16
-rw-------. 1 root root  786 Oct 14 09:35 authorized_keys
-rw-------. 1 root root 1675 Oct 13 08:24 id_rsa
-rw-r--r--. 1 root root  393 Oct 13 08:24 id_rsa.pub
-rw-r--r--. 1 root root  448 Oct 13 12:51 known_hosts

sshd가 “데몬 모드”에서 루트 파일에 액세스 할 수 있는지 묻습니다. 이 질문에 가장 가까운 대답은 다음과 같습니다.

# netstat -ntap | grep 22
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      19847/sshd
# ps -ef | grep 19847
root     19847     1  0 09:58 ?        00:00:00 /usr/sbin/sshd

sshd가 루트로 실행 중이면 자체 파일에 액세스하는 방법을 모르겠습니다. SELinux가 원인 일 수 있습니까?



답변

예, SELinux가 원인 일 수 있습니다. .sshDIR은 아마 잘못 표시됩니다. 을보십시오 /var/log/audit/audit.log. 라벨이 붙어 있어야합니다 ssh_home_t. 로 확인하십시오 ls -laZ. restorecon -r -vv /root/.ssh필요한 경우 실행하십시오 .


답변

나는 같은 문제가 있었다. 제 경우에는 restorecon과 chcon이 작동하지 않았습니다.

selinux를 비활성화하고 싶지 않았습니다. 많은 연구 끝에 마침내 홈 디렉토리가 다른 곳 (NFS)에서 마운트 되었기 때문이라고 생각했습니다. 나는 이 버그 보고서 를 발견 했다.

나는 달렸다 :

> getsebool use_nfs_home_dirs
use_nfs_home_dirs --> off

use_nfs_home_dirs가 꺼져 있는지 확인한 후 다음을 수행하십시오.

sudo setsebool -P use_nfs_home_dirs 1

켜십시오.

이제 비밀번호를 입력하지 않고 키를 사용하여 내 컴퓨터로 ssh 할 수 있습니다. use_home_nfs_dirs 부울을 전환하면 나에게 필요한 것이 었습니다.


답변

Mark Wagner의 답변에 추가하려면 사용자 정의 홈 디렉토리 경로를 사용하는 경우 (예 🙂 /homeSELinux 보안 컨텍스트를 설정해야합니다. 이를 위해 예를 들어에 사용자 홈 디렉토리가있는 경우 다음을 /myhome실행하십시오.

semanage fcontext -a -e /home /myhome
restorecon -vR /myhome


답변

연결을 테스트 할 때 다른 키를 사용하는 것 같습니다 (0x7f266e1a8840 vs 0x7f85527ef230). ‘ssh -v example.com’을 사용하여 데몬으로 실행되고 디버그 모드에서 sshd에 연결하고 “RSA 공개 키 제공”문자열에서 ssh가 사용하는 키를 찾으십시오.


답변