如何将 openssh sftp 命令与从命令行指定的 RSA/DSA 密钥一起使用

Adi*_*ban 46 ssh sftp rsa dsa

Openssh ssh 和 scp 命令提供了一个-i命令行选项来指定用于身份验证的 RSA/DSA 密钥的路径。

查看 sftp 手册页,我找不到指定 RSA/DSA 密钥的方法。

我正在寻找一种方法来启动一个 sftp 会话,该会话将使用指定的 RSA/DSA 密钥,而不是 ~/.ssh/id_{dsa,rsa} 密钥。

我在 Linux 上尝试了 OpenSSH sftp 客户端……但它在其他平台上应该有相同的选项。

dmo*_*ati 50

一种可能的选择是使用sftp -oIdentityFile=/path/to/private/keyfile. 需要更多信息来说明这是否适合您。似乎在 Mac/Linux 下工作。


slu*_*man 22

您可以简单地将-i参数用于 sftp 或 ssh 命令。

sftp -i /path/to/private/keyfile ...
Run Code Online (Sandbox Code Playgroud)

如果 -i 选项不可用,您可以使用 -o 选项,语法如下:

sftp -oIdentityFile=/path/to/private/keyfile ...
Run Code Online (Sandbox Code Playgroud)

  • sftp 没有 -i 选项,这大概是 OP 提出这个问题的原因。 (4认同)

use*_*517 10

您可以为连接创建备用配置文件,并使用-F开关告诉 ssh 使用它。使用内容创建一个配置文件,例如 ~/.ssh/config.sftp

Host remote.host.tld
User RemoteUserName
IdentityFile /path/to/atlernate/identityfile
Run Code Online (Sandbox Code Playgroud)

然后像这样调用sftp

sftp -F ~/.ssh/config.sftp remote.host.tld
Connecting to remote.host.tld...
Enter passphrase for key '/path/to/atlernate/identityfile':
sftp>
Run Code Online (Sandbox Code Playgroud)

上面的配置将备用键的使用(当使用此配置文件时)限制为 remote.host.tld 上的用户 RemoteUserName。

查看ssh_confg的手册页以了解备用配置文件的用法