나는 고전적인 SSH 키 문제에 대해 가능한 한 많은 버그 수정을 수행했습니다. 공개 키와 개인 키를 "올바르게" 설정했지만 비밀번호 없는 로그인은 여전히 작동하지 않습니다. 세부 사항:
첫째, 다른 권한 문제에 대해 읽고 싶어하는 사람은 아무도 없다는 것을 알고 있습니다.
~$ ls -lhd $HOME
drwx------. 28 mrkelly mrkelly 4.0K May 13 16:23 /mnt/driveB/mrkelly
~$ ls -lhd $HOME/.ssh
drwx------. 2 mrkelly mrkelly 4.0K May 13 15:37 /mnt/driveB/mrkelly/.ssh
~$ ls -lh $HOME/.ssh
total 24K
-rwx------. 1 mrkelly mrkelly 1.7K May 13 15:37 authorized_keys
-rwx------. 1 mrkelly mrkelly 668 May 13 15:20 id_dsa
-rwx------. 1 mrkelly mrkelly 625 May 13 15:20 id_dsa.pub
-rwx------. 1 mrkelly mrkelly 1.7K May 13 15:11 id_rsa
-rwx------. 1 mrkelly mrkelly 417 May 13 15:11 id_rsa.pub
-rwx------. 1 mrkelly mrkelly 980 May 13 14:57 known_hosts
/$ ll -d /
dr-xr-xr-x. 17 root root 4.0K May 14 12:21 /
/$ ll -d /mnt
drwxr-xr-x. 4 root root 4.0K Nov 18 04:33 /mnt
/$ ll -d /mnt/driveB
drwxr-xr-x. 4 root root 4.0K May 13 17:31 /mnt/driveB
~$ uname -a
Linux action-jackson.stanford.edu 3.19.7-200.fc21.x86_64 #1 SMP Thu May 7 22:00:21 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
SELinux가 이와 같은 상황에서 흔히 사용되는 악당이라는 것을 알고 이를 비활성화했습니다.
~$ sudo systemctl status selinux
● selinux.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
저는 호스트 시스템의 관리자이므로 SSHD 서버 측 서비스에 하나의 터미널을 사용하고 클라이언트로 다른 터미널을 사용합니다.
먼저 작업 버전은 다음과 같습니다.
호스트 터미널(sshd 비활성화됨):
~$ sudo /usr/sbin/sshd -d debug1: sshd version OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015 debug1: key_parse_private2: missing begin marker debug1: read PEM private key done: type RSA debug1: private host key: #0 type 1 RSA debug1: key_parse_private2: missing begin marker debug1: read PEM private key done: type ECDSA debug1: private host key: #1 type 3 ECDSA debug1: private host key: #2 type 4 ED25519 debug1: rexec_argv[0]='/usr/sbin/sshd' debug1: rexec_argv[1]='-d' Set /proc/self/oom_score_adj from 0 to -1000 debug1: Bind to port 22 on 0.0.0.0. Server listening on 0.0.0.0 port 22. debug1: Bind to port 22 on ::. Server listening on :: port 22.
(우리는 "클라이언트" 터미널을 사용하여 로그인할 때까지 여기에 있습니다. :)
debug1: Server will not fork when running in debugging mode. debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8 debug1: inetd sockets after dupping: 3, 3 Connection from 127.0.0.1 port 49966 on 127.0.0.1 port 22 debug1: Client protocol version 2.0; client software version OpenSSH_6.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1 debug1: SELinux support enabled [preauth] debug1: ssh_selinux_change_context: setting context from 'unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023' to 'unconfined_u:unconfined_r:sshd_net_t:s0-s0:c0.c1023' [preauth] debug1: permanently_set_uid: 74/74 [preauth] debug1: list_hostkey_types: ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 [preauth] debug1: SSH2_MSG_KEXINIT sent [preauth] debug1: SSH2_MSG_KEXINIT received [preauth] debug1: kex: client->server aes128-ctr [email protected] none [preauth] debug1: kex: server->client aes128-ctr [email protected] none [preauth] debug1: kex: [email protected] need=16 dh_need=16 [preauth] debug1: kex: [email protected] need=16 dh_need=16 [preauth] debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth] debug1: SSH2_MSG_NEWKEYS sent [preauth] debug1: expecting SSH2_MSG_NEWKEYS [preauth] debug1: SSH2_MSG_NEWKEYS received [preauth] debug1: KEX done [preauth] debug1: userauth-request for user mrkelly service ssh-connection method none [preauth] debug1: attempt 0 failures 0 [preauth] debug1: PAM: initializing for "mrkelly" debug1: PAM: setting PAM_RHOST to "localhost.localdomain" debug1: PAM: setting PAM_TTY to "ssh" debug1: userauth-request for user mrkelly service ssh-connection method publickey [preauth] debug1: attempt 1 failures 0 [preauth] debug1: test whether pkalg/pkblob are acceptable [preauth] debug1: temporarily_use_uid: 1000/1000 (e=0/0) debug1: trying public key file /mnt/driveB/mrkelly/.ssh/authorized_keys debug1: fd 4 clearing O_NONBLOCK Found matching RSA key: d7:9e:aa:54:63:d7:2d:87:d3:b1:0e:83:3b:70:27:d4 debug1: restore_uid: 0/0 Postponed publickey for mrkelly from 127.0.0.1 port 49966 ssh2 [preauth] debug1: userauth-request for user mrkelly service ssh-connection method publickey [preauth] debug1: attempt 2 failures 0 [preauth] debug1: temporarily_use_uid: 1000/1000 (e=0/0) debug1: trying public key file /mnt/driveB/mrkelly/.ssh/authorized_keys debug1: fd 4 clearing O_NONBLOCK Found matching RSA key: d7:9e:aa:54:63:d7:2d:87:d3:b1:0e:83:3b:70:27:d4 debug1: restore_uid: 0/0 debug1: ssh_rsa_verify: signature correct debug1: do_pam_account: called Accepted publickey for mrkelly from 127.0.0.1 port 49966 ssh2: RSA d7:9e:aa:54:63:d7:2d:87:d3:b1:0e:83:3b:70:27:d4 debug1: monitor_child_preauth: mrkelly has been authenticated by privileged process debug1: monitor_read_log: child log fd closed debug1: SELinux support enabled debug1: PAM: establishing credentials User child is on pid 8196 debug1: PAM: establishing credentials debug1: permanently_set_uid: 1000/1000 debug1: Entering interactive session for SSH2. debug1: server_init_dispatch_20 debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384 debug1: input_session_request debug1: channel 0: new [server-session] debug1: session_new: session 0 debug1: session_open: channel 0 debug1: session_open: session 0: link with channel 0 debug1: server_input_channel_open: confirm session debug1: server_input_global_request: rtype [email protected] want_reply 0 debug1: server_input_channel_req: channel 0 request x11-req reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req x11-req debug1: channel 1: new [X11 inet listener] debug1: channel 2: new [X11 inet listener] debug1: server_input_channel_req: channel 0 request pty-req reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req pty-req debug1: Allocating pty. debug1: session_new: session 0 debug1: SELinux support enabled debug1: session_pty_req: session 0 alloc /dev/pts/4 debug1: server_input_channel_req: channel 0 request env reply 0 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req env debug1: server_input_channel_req: channel 0 request env reply 0 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req env debug1: server_input_channel_req: channel 0 request shell reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req shell Starting session: shell on pts/4 for mrkelly from 127.0.0.1 port 49966 debug1: Setting controlling tty using TIOCSCTTY.
고객:
~$ ssh -v `whoami`@localhost OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: Connecting to localhost [127.0.0.1] port 22. debug1: Connection established. debug1: identity file /mnt/driveB/mrkelly/.ssh/id_rsa type 1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_rsa-cert type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_dsa type 2 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_dsa-cert type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ecdsa type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ecdsa-cert type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ed25519 type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr [email protected] none debug1: kex: client->server aes128-ctr [email protected] none debug1: kex: [email protected] need=16 dh_need=16 debug1: kex: [email protected] need=16 dh_need=16 debug1: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA 8d:cb:f2:94:da:97:7b:0d:ee:e6:bb:8e:3f:41:ae:d8 debug1: Host 'localhost' is known and matches the ECDSA host key. debug1: Found key in /mnt/driveB/mrkelly/.ssh/known_hosts:3 debug1: ssh_ecdsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering RSA public key: /mnt/driveB/mrkelly/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 279 debug1: key_parse_private2: missing begin marker debug1: read PEM private key done: type RSA debug1: Authentication succeeded (publickey). Authenticated to localhost ([127.0.0.1]:22). debug1: channel 0: new [client-session] debug1: Requesting [email protected] debug1: Entering interactive session. debug1: Requesting X11 forwarding with authentication spoofing. debug1: Sending environment. debug1: Sending env LANGUAGE = debug1: Sending env LANG = en_US.UTF-8 Last login: Wed May 13 15:58:17 2015 from localhost.localdomain Environment: LANGUAGE= LANG=en_US.UTF-8 USER=mrkelly LOGNAME=mrkelly HOME=/mnt/driveB/mrkelly PATH=/usr/local/bin:/usr/bin MAIL=/var/mail/mrkelly SHELL=/bin/zsh SSH_CLIENT=127.0.0.1 49967 22 SSH_CONNECTION=127.0.0.1 49967 127.0.0.1 22 SSH_TTY=/dev/pts/4 TERM=xterm-256color DISPLAY=localhost:11.0 SELINUX_ROLE_REQUESTED= SELINUX_LEVEL_REQUESTED= SELINUX_USE_CURRENT_RANGE= XDG_SESSION_ID=21 XDG_RUNTIME_DIR=/run/user/1000 XDG_SEAT=seat0 XDG_VTNR=1 Running /usr/bin/xauth remove unix:11.0 /usr/bin/xauth add unix:11.0 MIT-MAGIC-COOKIE-1 62951eb22f06d56df8189ee23126a19e
(직장에서는 비밀번호 없이 로그인하세요)
이제 sshd.service를 다시 시작하고 작동하지 않는 버전을 표시합니다.
호스트 터미널
sudo systemctl start sshd
고객
~$ ssh -v `whoami`@localhost OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: Connecting to localhost [127.0.0.1] port 22. debug1: Connection established. debug1: identity file /mnt/driveB/mrkelly/.ssh/id_rsa type 1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_rsa-cert type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_dsa type 2 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_dsa-cert type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ecdsa type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ecdsa-cert type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ed25519 type -1 debug1: identity file /mnt/driveB/mrkelly/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr [email protected] none debug1: kex: client->server aes128-ctr [email protected] none debug1: kex: [email protected] need=16 dh_need=16 debug1: kex: [email protected] need=16 dh_need=16 debug1: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA 8d:cb:f2:94:da:97:7b:0d:ee:e6:bb:8e:3f:41:ae:d8 debug1: Host 'localhost' is known and matches the ECDSA host key. debug1: Found key in /mnt/driveB/mrkelly/.ssh/known_hosts:3 debug1: ssh_ecdsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering RSA public key: /mnt/driveB/mrkelly/.ssh/id_rsa debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Offering DSA public key: /mnt/driveB/mrkelly/.ssh/id_dsa debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Trying private key: /mnt/driveB/mrkelly/.ssh/id_ecdsa debug1: Trying private key: /mnt/driveB/mrkelly/.ssh/id_ed25519 debug1: Next authentication method: keyboard-interactive Password:
(그게 다야).
마지막 몇 마디: 최근에 설치 드라이브를 다시 포맷해야 했고, 다른 드라이브에 저장된 폴더로 작업하고 있었습니다. Fedora 21을 재설치할 때 해당 드라이브에 홈 디렉터리를 강제로 생성해야 했지만 다른 드라이브에 대한 마운트 지점을 생성한 후 이전 홈 디렉터리의 백업 버전을 가리키도록 사용자 계정을 전환했습니다.
편집: 비밀번호 없는 로그인은 다음 호출을 통해서도 작동합니다.
/usr/sbin/sshd -D
(데몬은 없지만 디버그 메시지는 없습니다)
/usr/shbin/sshd
(데몬을 호출하기 때문에 임시 해결 방법인 것 같습니다.)
EDIT2: sudo journalctl -u sshd
이후 출력 sudo systemctl restart sshd
(로깅 수준 debug3)
제출 글자 수 제한에 도달하여 링크를 걸어드립니다.Dropbox의 일반 텍스트 파일출력으로.
당신이 제공할 수 있는 도움에 감사드립니다!
답변1
이는 홈 디렉터리가 이상한 위치에 있어서 발생하는 SELinux 문제입니다. 비활성화하기 위해 수행한 작업은 그렇지 않았습니다. SELinux는 서비스가 아니라 단지 systemctl status selinux
정보를 제공 할 뿐입니다.저것("찾을 수 없음(이유: 해당 파일이나 디렉터리가 없음)").
너할 수 있다SELinux를 실행 setenforce permissive
하거나 비활성화하지만 이는 집 열쇠를 한 번 넣는 것을 잊어버렸기 때문에 집 문이 열려 있는 것과 같습니다. 달리기는 chcon -t ssh_home_t ~/.ssh/
트릭을 수행해야합니다.
내가 어떻게 알아? ~/.ssh
파일 형식 때문에내 거체계. 하지만 나는할 수 있다sepolicy
패키지에서 설치되고 policycoreutils-devel
실행되어 실제 정책을 문서화하는 매뉴얼 페이지를 sepolicy manpage -t ssh_d
생성합니다 .ssh_selinux.8
정말로요.최대/home
이 모든 것을 잊어버리고 대신 드라이브를 마운트 /mnt/driveB
하고 실행하는 것이 좋습니다 restorecon -R -v /home
.
답변2
SELinux 입니다. 중지하고 비활성화하더라도 systemctl
계속 사용해야 합니다 /usr/bin/setenforce 0
. 이제 비밀번호 없는 로그인이 예상대로 작동합니다.
답변3
나는 NFS 공유를 기반으로 사용자의 홈 디렉터리에 대한 SSH 시도가 반복적으로 거부되고 (디버그/자세한) 출력에 다음과 같은 암호 메시지만 기록되는 비슷한 문제에 직면했습니다 ssh
.
debug1: key_parse_private2: missing begin marker
다른 답변에서 볼 수 있듯이 이는 SELinux 문제인 것으로 나타났습니다. 그러나 SELinux 적용을 완전히 비활성화하는 것보다 더 세분화된 솔루션이 있는 것 같습니다.
호스트에서는제공하다홈 디렉터리에서 다음 명령을 실행하여 기본적으로 사용자의 홈 디렉터리가 포함된 디렉터리와 동일한 방식으로 사용자의 홈 디렉터리가 포함된 디렉터리를 표시하도록 SELinux에 지시합니다 /home
.
sudo semanage fcontext -a -e /home /path/to/custom/homedir/container/on/server
그런 다음 다음 명령을 실행하여 홈 디렉터리에서 SELinux 레이블을 재귀적으로 재설정합니다.
sudo restorecon -R /path/to/custom/homedir/container/on/server
NFS를 사용하는 경우(저의 경우) 홈 디렉토리를 마운트하는 각 클라이언트에서 다음 추가 명령을 실행하여 NFS를 사용하여 홈 디렉토리를 마운트할 수 있도록 SELinux를 설정합니다.
sudo setsebool -P use_nfs_home_dirs on
인용하다: