(关于这个问题的大多数线程都与AWS或GitHub有关。我的线程两者都不是。这是一个简单的Digital Ocean CentOS 8服务器。)
我的旧Macbook连接到我的SSH服务器没有任何问题:,使用
ssh -2 -p 5555 -i /Users/Me/.ssh/id_rsa me@99.99.99.99
(端口号和IP更改当然是为了隐私。)
我买了一台新的Macbook Pro,像往常一样设置了ssh-keygen
,然后手动将id_rsa.pub
移动到服务器的.ssh/authorized_keys
。在服务器上,我以root用户身份登录时使用nano将其添加到授权密钥文件中。以下是以root用户身份登录时服务器上.ssh
目录的样子:
990971649 -rw-------. 1 root root 2722 Jul 7 07:52 authorized_keys
990971651 -rw-------. 1 root root 3389 Jan 10 2021 id_rsa
990971652 -rw-------. 1 root root 747 Jan 10 2021 id_rsa.pub
但是,尽管在服务器上的authorized_keys中添加了id_rsa.pub内容,我还是收到了以下错误:
me@99.99.99.99: Permission denied (publickey)
这个问题上的大多数线程都已经通过添加一些参数"解决"了,但我在服务器上的ssh_config
设置似乎很好。。。这是我的旧Macbook的作品!以下是服务器设置--
Protocol 2
Port 5555
LoginGraceTime 60
ClientAliveInterval 120
ClientAliveCountMax 3
MaxSessions 6
AllowUsers root
PermitEmptyPasswords no
PasswordAuthentication no
PermitRootLogin yes
X11Forwarding no
MaxAuthTries 6
IgnoreRhosts yes
AllowTcpForwarding no
AllowAgentForwarding no
Compression no
TCPKeepAlive no
UseDNS no
HostbasedAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey
还有什么可能出错?
要解决OpenSSH 9.0p1默认情况下使用SHA-1哈希算法禁用RSA签名的问题,可以按照以下步骤修改ssh_config文件:
sudo vi /etc/ssh/ssh_config
在ssh_config的底部添加以下行:
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
sshd_config是OpenSSH服务器的配置文件。ssh_config是OpenSSH客户端的配置文件。确保不要混淆它们
您需要编辑服务器配置文件,而不是客户端配置文件(ssh_config)
在sshd_config中添加或编辑
PubkeyAuthentication yes
如果你不想用密码登录,只需密钥也可以编辑:
但如果服务器不在同一位置,请先尝试使用密钥登录,然后将其编辑为否!
PasswordAuthentication no
不要以root安全身份登录!
PermitRootLogin no
您可以使用ssh复制id将密钥复制到服务器
ssh-copy-id -i ~/.ssh/[KEY] -p [PORT] [user]@[IP]
更新:
取消对sshd_config中所有这些行的注释,并尝试仅使用允许/现有用户的密码登录,以查明是否存在其他错误:
每次更改SSH服务器文件时,不要忘记重新启动SSH服务器:
#LoginGraceTime 60
#ClientAliveInterval 120
#ClientAliveCountMax 3
#MaxSessions 6
#AllowUsers root
#PermitEmptyPasswords no
PasswordAuthentication yes
#PermitRootLogin yes
#X11Forwarding no
#MaxAuthTries 6
#IgnoreRhosts yes
#AllowTcpForwarding no
#AllowAgentForwarding no
#Compression no
#TCPKeepAlive no
#UseDNS no
#HostbasedAuthentication no
#PubkeyAuthentication yes
#AuthenticationMethods publickey