如何使用openssh sftp命令和从命令行指定的RSA / DSA密钥

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

看看sftp手册页,我无法find指定RSA / DSA密钥的方法。

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

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

一个潜在的select是使用sftp -oIdentityFile=/path/to/private/keyfile 。 需要更多信息来说明这是否适合你。 似乎在Mac / Linux下工作。

你可以简单地使用你的sftp或ssh命令的-i参数。

 sftp -i /path/to/private/keyfile ... 

如果-i选项不可用,则可以使用-o选项,其语法如下所示:

 sftp -oIdentityFile=/path/to/private/keyfile ... 

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

 Host remote.host.tld User RemoteUserName IdentityFile /path/to/atlernate/identityfile 

然后像这样调用sftp

 sftp -F ~/.ssh/config.sftp remote.host.tld Connecting to remote.host.tld... Enter passphrase for key '/path/to/atlernate/identityfile': sftp> 

上面的configuration限制了在remote.host.tld中使用备用密钥(当使用此configuration文件时)到用户RemoteUserName。

查看ssh_confg的手册页,了解备用configuration文件的用法