连接到 CentOS 7.9 并出现 SSH 错误 Permission Denied

Connecting to CentOS 7.9 with SSH error Permission Denied

我尝试使用以下命令在端口 22 上使用 Root 用户连接到我的 Linux centOS 服务器:

ssh -p 22 root@ip

但是连接return这个错误:

root@ip: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

我该怎么办?

首先,您必须使用以下命令更改服务器计算机上的权限:

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

然后在 /etc/ssh/sshd_config 中编辑为:

sudo sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config;

运行:

systemctl stop sshd.service

和运行:

systemctl enable sshd.service

然后 运行:

systemctl start sshd.service

之后:

systemctl status sshd.service

并检查输出。如果一切顺利,从现在开始每次启动时都应该有 ssh 服务。