How to use openssh sftp command with a RSA/DSA key specified from the command line

Solution 1:

One potential option is to use sftp -oIdentityFile=/path/to/private/keyfile. Need more info to say whether that will work for you. Seems to work under Mac/Linux.

Solution 2:

You can simply use the -i argument for your sftp or ssh command.

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

If the -i option is not available, you can use the -o option with a syntax like:

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

Solution 3:

You can create an alternate config file for the connection and use the -F switch to tell ssh to use it. create a config file e.g. ~/.ssh/config.sftp with the contents

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

then call sftp like so

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

The config above restricts the use of the alternate key (when this config file is used) to user RemoteUserName on remote.host.tld.

Have a look at the man page for ssh_confg for the usage of the alternate config file

Tags:

Sftp

Ssh

Rsa

Dsa