无密码 SSH (Windows --> CentOS)

tch*_*rty 1 ssh centos

我正在尝试使无密码 SSH 身份验证从 Windows 7 机器工作到本地服务器。

  1. Windows 机器:我在这台机器上的登录名是MY_LOGIN_NAME. 我使用 Cygwin 作为命令行。

  2. CentOS 5.5 服务器:我在这台服务器上有管理员权限;以root.

这是我到目前为止所做的:

  1. 登录到MY_LOGIN_NAMEWindows 机器上,我ssh-config-user从 Cygwin 命令行编辑。这在(至少)中创建了 RSA 公钥和私钥 C:/Users/MY_LOGIN_NAME/.ssh

  2. 我将公钥复制到服务器.ssh使用scp.

    scp id-rsa.pub root@xxx.xxx.xx.xx:.ssh/id-rsa.pub

  3. 然后我尝试使用ssh如下方式登录服务器:

    ssh -i id_rsa root@xxx.xxx.xx.xx

但它仍然要求我输入密码。我错过了什么?

小智 5

问题是您的第 2 步。您用 Cygwin 公钥覆盖了 root@xxx.xxx.xx.xx 公钥。那不是你想要的。

相反,您应该将您的公钥添加到 root@xxx.xxx.xx.xx 授权密钥中。这可以通过手动将您的 id-rsa.pub 附加到 /root/.ssh/autorized_keys(在 CentOS 上)或在 Cygwin 上自动运行ssh-copy-id来完成。

ssh-copy-id root@xxx.xxx.xx.xx
Run Code Online (Sandbox Code Playgroud)

它会提示您输入密码,然后您应该没问题。

另外,如果不方便的话,你应该恢复root@xxx.xxx.xx.xx 公钥,或者生成一个新的对。