The Computer Oracle

How do I use my keyfile to sftp transfer data from one server to another

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------


Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle3

--

Chapters
00:00 How Do I Use My Keyfile To Sftp Transfer Data From One Server To Another
00:25 Answer 1 Score 0
00:35 Accepted Answer Score 46
00:48 Answer 3 Score 8
01:50 Answer 4 Score 2
02:25 Thank you

--

Full question
https://superuser.com/questions/483593/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#unix #authentication #ssh #amazonec2 #sftp

#avk47



ACCEPTED ANSWER

Score 46


Try:

sftp -o "IdentityFile=keyname" jay@server.name.com

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




ANSWER 2

Score 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



ANSWER 3

Score 2


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

sftp -i ./privateFilePath.key username@url.com

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 :)




ANSWER 4

Score 0


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