我试图在我的 WSL(Ubuntu 16)上设置与本地主机的公钥 ssh 连接,而无需密码登录。
但每次我一直被要求输入密码。当我使用port22时,我的密码甚至无法使用,但是当我使用其他端口(如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
请给一些建议。