33

I cant scp, the other server only takes sftp connections.

Currently, I am trying to do

sftp [email protected]:/files> put -r ~/

-i keyname does not work, just resolves with illegal option -- i.

Jay
  • 547
  • 2
  • 5
  • 8

4 Answers4

45

Try:

sftp -o "IdentityFile=keyname" [email protected]

You can use -o to pass any option that's valid in ~/.ssh/config.

Celada
  • 2,290
  • 14
  • 9
  • Nailed it. thanks! how do i keep it there normally? – Jay Oct 05 '12 at 00:00
  • 1
    I don't know what you mean by "keep it there normally". If you mean that you want the `IdentityFile` option to always automatically be given, check out [UtahJarhead](http://superuser.com/users/127831/utahjarhead)'s answer about putting it in `~/.ssh/config` – Celada Oct 05 '12 at 01:38
8

Copy your PUBLIC key to the server using traditional means.

On server:

  • Create .ssh if it doesn't exist:
[[ ! -d "${HOME}/.ssh" ]] && mkdir -p "${HOME}/.ssh"
  • Implement the public key:
cat /path/to/public_key.pub >> "${HOME}/.ssh/authorized_keys"
  • Set appropriate permissions. OpenSSH is VERY ANAL about the permissions of the files in question:
chmod go-rwx "${HOME}" "${HOME}/.ssh/authorized_keys"

After that, you should be able to log in from the client using the PRIVATE key. To automate a transfer, you want to use a batch file, which is just a text file containing a list of commands to execute.

echo "put filename.foo /safe/path/filename.foo" >> /tmp/batchfile.txt
sftp -b /tmp/batchfile.txt -oIdentityFile=/path/to/private_key user@host

Alternatively, feel free to create a ~/.ssh/config file in ssh_config format so you can just type this in the future:

sftp -b /tmp/batchfile.txt host

Sample contents of ~/.ssh/config

Host the_hostname
    User user_name
    IdentityFile /path/to/private_key
UtahJarhead
  • 2,027
  • 2
  • 13
  • 15
0

I got into this issue recently and what worked for me in my macbook default terminal setup is the following

sftp -i ./privateFilePath.key [email protected]

Note you might be promoted with UNPROTECTED PRIVATE KEY FILE! message in which case you need to run this command to make sure your private key is not accessible by others.

chmod 600 privateFilePath.key 

In some cases you need to put sudo in front of the command, this is only if you are working in a admin protected directory

I wish thats helpful :)

0

If you are looking to setup sftp on ec2, this article might help

Anshu
  • 107
  • 2
  • Sorry, it really didnt. – Jay Oct 05 '12 at 00:01
  • 1
    This "answer" has nothing to contribute to the question. Worse, it is just a link to a page that will someday disappear. – John Mayor Oct 02 '16 at 20:57
  • Well wouldn't you know it, it did disappear, for anyone caring to find out what the article was, take a look here. https://web.archive.org/web/20150107025158/https://rmtheis.wordpress.com/2011/07/03/setting-up-an-sftp-site-on-amazon-web-services-ec2-creating-an-account-to-share-with-a-third-party-and-restricting-that-account-to-allow-only-sftp/ – Mike Elahi Apr 06 '23 at 14:59