我有一台家用电脑和一台服务器。我希望服务器能够通过 SSH 连接到我的家用电脑而无需密码。我按照各种教程操作,可以从家到服务器没有密码。一切正常。当我尝试逆转该过程并从服务器到家我得到一个权限被拒绝(公钥)错误。我可以使用密码正常登录两台机器。
详细尝试的相关内容如下:
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: No more authentication methods to try.
Permission denied (publickey,keyboard-interactive).
我家里的电脑上的 /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
#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 ~/.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 yes
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication yes
# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no
# 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 /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 no
家里的电脑运行的是Ubuntu,服务器是CentOS。
答案1
您的 AuthorizedKeysFile 行应为AuthorizedKeysFile .ssh/authorized_keys
。同时请确保您的 .ssh 目录上的权限为700
,并且您的 authorized_keys 文件的权限为600
。
答案2
您是否在服务器上创建了用户密钥,然后将该公钥复制到主服务器上的 .ssh/authorized_keys 中?
更简单的选择是使用通常的“ssh-keygen ...”命令创建密钥,然后使用“ssh-copy-id”命令将公钥移动到另一台机器。
ssh-keygen (follow the prompts)
ssh-copy-id -i ~/.ssh/id_rsa.pub me@home_system
当然,将 id_rsa.pub 更改为您选择的密钥方法(ssh-keygen 的 cmd 行选项)。
请记住,ssh 密钥是单向的...从这里到那里。因此,如果您想以另一种方式使用无密码登录,您也必须进行设置。
答案3
我建议您不要以 root 用户身份使用 ssh - 如果这样做,您可能需要解决一台或两台主机上的良好配置问题。以下是我建议的一些更改:
PermitRootLogin 是
那确实不应该。这是合理的额外保护层。
RSA身份验证 是
将其改为否。它指的是 ssh v1,如果您有发言权,您不会想要它。
允许空密码 是
改为否。
ChallengeResponseAuthentication 是
如果您正在使用公钥,那么您不必启用 CHAP,所以不要启用。
考虑一下这些:
最大授权尝试次数 3
让攻击者重新进行初始握手,作为会话中三次失败尝试的惩罚
MaxStartups 5 # 最大并发 ssh 会话数,对于家庭用户来说 5 就足够了
您可能应该更改此行:
AuthorizedKeys文件 ~/.ssh/authorized_keys
对此
授权密钥文件 .ssh/authorized_keys
答案4
BinaryOrganic...我看了你的帖子,发现你的 /etc/ssh/sshd_config 文件有一个条目设置,这导致了你的失败和那个错误消息。
过去我和其他人使用 x2go 客户端登录 Ubuntu/Debian x2goservers 时没有遇到任何问题。
然而,在过去一两年的 Ubuntu 和 Debian 操作系统更新中,发生了一些变化,导致需要输入用户 ID 和密码的正常 x2goclient 会话配置文件失败,并在客户端上显示一条错误消息,内容如下:
访问被拒绝。可以继续的身份验证:publickey,keyboard-interactive
我终于找到了这种行为改变的原因,并且下面介绍了解决方法。
与 x2goserver 建立终端会话并编辑 /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config
在 /etc/ssh/sshd_config(示例从 Ubuntu 12.04 复制而来)中,您将看到以下条目:
*# 更改为“是”以启用质询-响应密码(注意某些 PAM 模块和线程的问题)
*# ChallengeResponseAuthentication 是
*# 更改为 no 以禁用隧道明文密码
密码验证否**
修复此更改 密码验证到 ”是的“保存文件并重新启动 ssh
sudo /etc/init.d/ssh 重启
Ubuntu 以前/旧版本失败和行为变化的原因。我安装了几个旧版本的 Ubuntu,最早是 Ubuntu 9.10,发现 Ubuntu Server 的安装改变了 /etc/ssh/sshd_config 文件的内容!
在旧系统中,PasswordAuthentication 的条目要么表示:
# 更改为 no 以禁用隧道明文密码
# 密码验证否
其中 PasswordAuthentication 行被注释掉...然后将其默认为“YES”
-或者-
密码验证行实际上已被取消注释,但设置为“是”
# 更改为 no 以禁用隧道明文密码
密码验证 是
因此,那些旧版本的操作系统和 x2go 可以使用登录 ID 和密码来工作。
在 Ubuntu 11.x 发布期间的某个时候,PasswordAuthentication 条目实际上被更改为“否”,就像在 Ubuntu 12.04 服务器中的情况一样,并且该行没有被注释掉,因此它处于活动状态......
# 更改为 no 以禁用隧道明文密码
密码验证否
这就是导致 x2go 使用密码登录失败并向用户显示以下错误消息的原因:
访问被拒绝。可以继续的身份验证:publickey,keyboard-interactive
我现在已经进行了此更改,并且我的服务器上不再出现问题,因此我想分享此信息,因为我对该错误消息的谷歌搜索显示,很多人在使用许多其他远程访问工具(freenx、x2go、NoMachine NX 等)时发布了有关相同错误的帖子。希望这对您也有帮助。