无法尝试其他身份验证方法。权限被拒绝(公钥)

无法尝试其他身份验证方法。权限被拒绝(公钥)

不久前,我在路由器后面设置了一个家庭网络,并使用 openssh 访问由我的笔记本电脑、妻子的上网本和我的台式机组成的网络,所有台式机都运行 l/x/ubuntu 12.04。一段时间内,这一直运行良好。

我现在只能访问上网本和其他两台电脑,但无法在笔记本电脑和台式机之间进行访问。我从未使用过 id_* 路由,因此 ~/.ssh 目录中没有 id_* 文件。

我尝试了论坛上建议的各种策略,例如删除 known_hosts 并将配置文件(例如将 PasswordAuthentication 更改为 no、yes 和注释掉)都试过了。但这些都不起作用。

我唯一能想到的是,我最近在笔记本电脑和台式机之间设置 vpn 网络,这可能改变了一些东西,从而扰乱了这两台机器之间 ssh 的工作。顺便说一句,我还没有设法让 vpn 工作(请参阅本论坛上的上一篇文章)。

我的桌面上的 /etc/ssh/sshd_config 文件是:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

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

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

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

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

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

Subsystem sftp internal-sftp #/usr/lib/openssh/sftp-server

# 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

Match User sftpuser #group sftponly
ChrootDirectory /media/Backups/ftp
X11Forwarding yes
AllowTcpForwarding yes 
ForceCommand internal-sftp

ssh -v laptop 命令输出:

OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /home/malapradej/.ssh/config
debug1: /home/malapradej/.ssh/config line 1: Applying options for laptop
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.0.2 [192.168.0.2] port 22.
debug1: Connection established.
debug1: identity file /home/malapradej/.ssh/id_rsa type -1
debug1: identity file /home/malapradej/.ssh/id_rsa-cert type -1
debug1: identity file /home/malapradej/.ssh/id_dsa type -1
debug1: identity file /home/malapradej/.ssh/id_dsa-cert type -1
debug1: identity file /home/malapradej/.ssh/id_ecdsa type -1
debug1: identity file /home/malapradej/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 [email protected]
debug1: kex: client->server aes128-ctr hmac-md5 [email protected]
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 1e:f2:57:81:28:8a:12:d3:7e:2d:04:c2:82:4f:43:72
debug1: Host '192.168.0.2' is known and matches the ECDSA host key.
debug1: Found key in /home/malapradej/.ssh/known_hosts:1
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
debug1: Next authentication method: publickey
debug1: Trying private key: /home/malapradej/.ssh/id_rsa
debug1: Trying private key: /home/malapradej/.ssh/id_dsa
debug1: Trying private key: /home/malapradej/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

答案1

谢谢你的帮助。问题解决了。我需要将 .ssh 的权限设置为 700。.ssh/ 的权限设置为 600确保在两台机器上都执行此操作。还更改 .ssh/ 的所有权。和 .ssh/给 root 用户,否则用户将无法访问配置文件中的任何信息。

sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/*
sudo chown -R User ~/.ssh/
sudo chgrp -R User ~/.ssh/

其中 User 是用户名。这对我来说很有效。

答案2

我知道这可能听起来像是一个愚蠢的建议。但我们遇到了这个问题:连接正常,但过了一段时间,它就停止工作了。因为一旦连接处于活动状态,就不可能知道身份验证何时停止生效。在我们的案例中,在更改其他用户的密钥时,该特定密钥也会被更改。因此,新连接不起作用,但当前连接仍然有效。

我确实建议您始终将公钥和私钥放在一起,这样您就可以进行比较甚至重新加载。另一件事是,尝试进行 ssh 连接以保证它不是指纹问题。在这两种情况下,sshfs 的 -v、-vv 和 -debug 可能很有用。此外,在主机上,尝试连接时使用 journalctl -f,它将显示尝试(如果发生),因此您可以确保连接没有被阻止......

答案3

另外检查一下你是否没有配置文件,~/.ssh并且没有条目PubkeyAuthentication=no

答案4

就我而言,我在调试信息中发现以下错误消息

debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa RSA SHA256:/m/qEkp4FQbzgofk3iHUDVfyjpZMFxX68UKPoTc766k
debug1: Authentications that can continue: publickey
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug1: Offering public key: /root/.ssh/id_ed25519 ED25519 SHA256:zTtrWi58QpPYwpzilta5vfmne6FFJ0C2J7ucmZI95U8
debug1: Authentications that can continue: publickey
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug1: Trying private key: /root/.ssh/id_xmss
debug1: No more authentication methods to try.

发现我的 ~/.ssh/ 文件夹中有多个文件,详细信息如下:

~/.ssh# ls
authorized_keys  config  config.bak  id_ed25519  id_ed25519.pub  id_rsa  id_rsa.pub  known_hosts

我删除了除 id_rsa 之外的所有 id_* 文件,问题就解决了。

相关内容