我已经在我的 Windows 机器上设置了一个 OpenSSH 服务器,并且能够成功地从 Windows 机器通过 SSH 连接到我的 Linux 机器(反之亦然)。
虽然我无法为其设置密钥认证……以下是我遵循的步骤
在 Windows 上——OpenSSH
C:\OpenSSH\bin> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Arpit/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/Arpit/.ssh/id_rsa.
Your public key has been saved in /home/Arpit/.ssh/id_rsa.pub.
The key fingerprint is:
b9:0c:33:15:9f:8a:bf:02:cf:80:43:7c:6e:42:07:52 Arpit@Windows-HOST
C:\OpenSSH\bin> scp "C:\Documents and Settings\Arpit\.ssh\id_rsa.pub" Arpit@Linux-HOST:
按照这些步骤尝试 ssh,但它要求输入密码才能连接
在 Linux 上
[arpit@Linux-HOST ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/arpit/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/arpit/.ssh/id_rsa.
Your public key has been saved in /home/arpit/.ssh/id_rsa.pub.
The key fingerprint is:
e8:ac:43:a5:52:d5:ca:11:ea:2f:ae:b9:b0:cb:ba:8e arpit@Linux-HOST
[arpit@Linux-HOST ~]$ ssh-copy-id -i /home/arpit/.ssh/id_rsa.pub arpit@Windows-HOST
arpit@Windows-HOST's password:
Now try logging into the machine, with "ssh 'arpit@Windows-HOST'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
还是没运气。有人能帮我解决吗?
答案1
您是否已将公钥复制到 Linux 机器中的 authorized_key 文件中?:
使用记事本打开“C:\Documents and Settings\Arpit.ssh\id_rsa.pub”文件,复制内容并附加到 Linux 机器上的 .ssh/authorized_key。然后重试
答案2
在我的客户端(Windows)上,我id_rsa.pub
的文件夹中有一个错误的文件~/.ssh/
。
删除此文件后,公钥认证就可以正常工作了。
我在这里找到了这个解决方案:https://superuser.com/a/1067189/724897
答案3
以防有人遇到和我一样的错误。如果你用记事本保存你的 id_rsa 密钥,它将是一个 txt 文件,openssh 将找不到它。为了解决这个问题,请打开 id_rsa,另存为,所有类型,然后将其命名为“id_rsa”带引号。这将保存它而不需要扩展名,openssh 再次喜欢你。
答案4
好吧,看起来除了用户目录(C:\Documents and Settings\[username]\.ssh
)目录之外,我们还需要将authorized_keys
文件复制到以下位置:
[OpenSSH Installation Directory]\etc\
一旦我在上述位置复制了远程主机的公钥,密钥认证就开始起作用了。