如何在SSHFS中指定密钥?

J L*_*J L 93 ssh key-authentication sshfs

我有一个我无法找到答案的问题。我有两台计算机,都运行 Ubuntu Linux 12.04。我已经设置了我的第一台计算机(“家”),以便能够使用公共/私有 RSA 密钥身份验证通过 SSH 连接到我的第二台计算机(“远程”)。

这不是第一个在我的家用计算机上使用密钥身份验证建立的 SSH 连接,因此我的家用计算机有几个 id_rsa 私钥文件(每个文件都用于不同的计算机以进行 SSH 连接)。因此,我能够成功SSH只有当我指定(在密钥文件ssh,该-i选项),使用ssh username@ipaddress -i path/to/keyfile/id_rsa.2

这很好用。但是,我也想使用sshfs挂载远程文件系统的 。虽然ssh使用多个密钥似乎很好,但我找不到sshfs使用正确私钥(“id_rsa.2”)的方法。

有没有办法sshfs做到这一点?

gol*_*cks 127

以下是对我有用的内容:

sshfs me@x.x.x.x:/remote/path /local/path/ -o IdentityFile=/path/to/key
Run Code Online (Sandbox Code Playgroud)

您可以通过man sshfs以下方式弄清楚:

-o SSHOPT=VAL ssh 选项(参见 man ssh_config)

man ssh_config

身份文件

指定从中读取用户的 DSA、ECDSA 或 DSA 身份验证身份的文件。

  • 注意事项:`IdentityFile=` 必须是绝对路径而不是相对路径。我今天学到了这个。 (3认同)
  • `IdentityFile` 路径注释。如果使用 `sudo` 运行 `sshfs`,在 `IdentityFile` 路径中使用 `~` 指的是 root 的家,这可能不是 RSA 文件所在的位置。改用`/Users/<username>/.ssh` 之类的东西。 (2认同)

小智 25

您需要做的是指定在~/.ssh/config文件中使用哪个私钥。例如:

Host server1.nixcraft.com
    IdentityFile ~/backups/.ssh/id_dsa
Host server2.nixcraft.com
    IdentityFile /backup/home/userName/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)


小智 8

sshfs -o ssh_command='ssh -i path/to/keyfile/id_rsa.2' username@ipaddress:/path /local/path
Run Code Online (Sandbox Code Playgroud)