在 CentOS 上安装 OpenSSH 服务后,您需要正确设置权限以确保服务器的安全性
sudo systemctl start sshd sudo systemctl enable sshd sudo vi /etc/ssh/sshd_config PubkeyAuthentication yes PasswordAuthentication no 这将禁用密码身份验证,只允许公钥身份验证。您可以根据需要启用密码身份验证,但要确保不要同时启用两者,因为这会降低安全性。
/var/run/sshd 目录的权限,以便只有 root 用户可以访问它:sudo chown root:root /var/run/sshd sudo chmod 755 /var/run/sshd /var/lib/ssh 目录的权限,以便只有 root 用户可以访问它:sudo chown root:root /var/lib/ssh sudo chmod 700 /var/lib/ssh /etc/ssh 目录的权限,以便只有 root 用户可以访问它:sudo chown root:root /etc/ssh sudo chmod 700 /etc/ssh sudo su sudo systemctl restart sshd 现在,您已经设置了 CentOS 上 OpenSSH 的权限。请确保您的服务器上的防火墙允许 SSH 连接,然后您可以使用私钥进行身份验证来连接到服务器。