공개 키를 사용하여 WSL에서 localhost로 SSH를 연결하지만 계속해서 비밀번호를 묻습니다.

공개 키를 사용하여 WSL에서 localhost로 SSH를 연결하지만 계속해서 비밀번호를 묻습니다.

비밀번호 로그인 없이 WSL(Ubuntu 16)의 localhost에 대한 공개 키 SSH 연결을 설정하려고 합니다.

하지만 매번 비밀번호를 묻는 메시지가 나타납니다. 포트 22를 사용하면 내 비밀번호가 작동하지 않지만 2222와 같은 다른 포트를 사용할 때는 적어도 내 비밀번호가 통과하지만 공개 키는 여전히 작동하지 않습니다.

이것은 다음을 사용할 때 얻는 결과입니다.sudo ssh -v -p 22 localhost

    OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /home/hadoop/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/hadoop/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/hadoop/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/hadoop/.ssh/id_ecdsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.4        IBM11.1.4040.491
debug1: match: OpenSSH_5.4 IBM11.1.4040.491 pat OpenSSH_5* compat 0x0c000000
debug1: Authenticating to localhost:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: [email protected] compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: [email protected] compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:jt2fTN1xeFtdB7ntfeQ5V8NnRxdDceejwwChS5hs3xw
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password
debug1: Next authentication method: password
root@localhost's password:
debug1: Authentications that can continue: password
Permission denied, please try again.
root@localhost's password:
debug1: Authentications that can continue: password
Permission denied, please try again.
root@localhost's password:
debug1: Authentications that can continue: password
debug1: No more authentication methods to try.
root@localhost: Permission denied (password).

~/.ssh 디렉터리의 모든 파일에 대한 권한은 다음과 같습니다.

 -rw------- 1 hadoop hadoop  404 Feb  7 23:00 authorized_keys
-rw-r--r-- 1 hadoop hadoop 1675 Feb  7 22:58 id_rsa
-rw-r--r-- 1 hadoop hadoop  404 Feb  7 22:58 id_rsa.pub
-rw-r--r-- 1 hadoop hadoop 1552 Feb  8 12:38 known_hosts

/etc/ssh 디렉토리의 파일에 대한 권한은 다음과 같습니다.

    -rw------- 1 root root    404 Feb  8 01:42 authorized_keys
-rw-r--r-- 1 root root    404 Feb  8 01:55 id_rsa.pub
-rw-r--r-- 1 root root 553122 Mar  4  2019 moduli
-rw-r--r-- 1 root root   1617 Feb  8 13:27 ssh_config
-rw------- 1 root root    227 Feb  7 21:46 ssh_host_ecdsa_key
-rw-r--r-- 1 root root    182 Feb  7 21:46 ssh_host_ecdsa_key.pub
-rw------- 1 root root    411 Feb  7 21:46 ssh_host_ed25519_key
-rw-r--r-- 1 root root    102 Feb  7 21:46 ssh_host_ed25519_key.pub
-rw------- 1 root root   1679 Feb  7 21:46 ssh_host_rsa_key
-rw-r--r-- 1 root root    402 Feb  7 21:46 ssh_host_rsa_key.pub
-rw-r--r-- 1 root root    338 May 21  2019 ssh_import_id
-rw-r--r-- 1 root root   3282 Feb  8 13:33 sshd_config

sshd_config 파일의 내용입니다.

#       $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 22
Protocol 2
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::1

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key

#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
RekeyLimit default none

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:

LoginGraceTime 2m
PermitRootLogin without-password
AllowUsers hadoop isaac root
StrictModes yes
MaxAuthTries 6
MaxSessions 10

PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2

AuthorizedPrincipalsFile none

AuthorizedKeysCommand none
AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

ssh_config 파일의 내용입니다.

 # This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *

    #   ForwardAgent no
    #   ForwardX11 no
    #   ForwardX11Trusted yes
    #   PasswordAuthentication yes
    #   HostbasedAuthentication no
    #   GSSAPIAuthentication no
    #   GSSAPIDelegateCredentials no
    #   GSSAPIKeyExchange no
    #   GSSAPITrustDNS no
    #   BatchMode no
       CheckHostIP yes
       AddressFamily any
    #   ConnectTimeout 0
       StrictHostKeyChecking ask
       IdentityFile /home/hadoop/.ssh/id_rsa
    #   IdentityFile /home/hadoop/.ssh/id_dsa
       IdentityFile /home/hadoop/.ssh/id_ecdsa
    #   IdentityFile /home/hadoop/.ssh/id_ed25519
       Port 22
       Protocol 2
    #   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
    #   MACs hmac-md5,hmac-sha1,[email protected]
    #   EscapeChar ~
    #   Tunnel no
    #   TunnelDevice any:any
    #   PermitLocalCommand no
    #   VisualHostKey no
    #   ProxyCommand ssh -q -W %h:%p gateway.example.com
    #   RekeyLimit 1G 1h
        SendEnv LANG LC_*
        HashKnownHosts yes
        GSSAPIAuthentication yes

몇 가지 제안을 해주세요.

답변1

debug1: Authentications that can continue: password

문제는 연결하려는 SSH 서버가 비밀번호 인증만 허용한다는 것입니다. 공개 키 인증을 수행하지 않으므로 클라이언트는 키를 사용하여 인증을 시도하지 않습니다.

공개 키 인증은 일반적으로 다음으로 구성됩니다.공개키 인증sshd_config의 옵션. 게시한 sshd_config에는 이 설정이 "yes"로 설정되어 있어 공개 키를 허용하게 됩니다.

실제 문제는 아마도 다음과 같습니다. ssh 클라이언트는 자신을 버전 7.6으로 식별하고 sshd_config 상단의 날짜는 OpenSSH 버전 7.5 정도에 해당합니다. 그러나 디버그 추적에는 다음이 있습니다.

debug1: Remote protocol version 2.0, remote software version OpenSSH_5.4        IBM11.1.4040.491

실제로 연결하는 SSH 서버는 IBM 공급업체 레이블이 있는 OpenSSH 5.4의 복사본으로 자신을 식별합니다. OpenSSH 5.4는 2010 버전이며 일반적으로 "IBM"으로 식별되지 않습니다.

내 생각에는 연결하려는 SSH 서버가 Ubuntu에서 제공하는 일반 SSHD가 아니며 게시한 sshd_config 파일을 사용하여 구성되지 않은 것 같습니다. 다른 방식으로 구성된 공급업체별 OpenSSH 버전에 연결하고 있습니다. 현재 구성에서는 공개 키 인증을 허용하지 않습니다.

관련 정보