How do I automate SFTP to get rid of the password prompt?

I need to perform SFTP automation (to get rid of the password prompt). How can I do this?

1

4 Answers

You need to set up a public/private key. How can I automate an SFTP transfer between two servers?

My suggestion is using SSH authorized_keys. You will need to create a key on the client side (using ssh-keygen) and then copy the public key to the target side.

client-machine% ssh-keygen -t rsa
client-machine% scp ~/.ssh/id_rsa.pub user@target-machine:~/.ssh/authorized_keys2

Note that if you want to access target-machine from two or more "clients", you can not copy the id_rsa.pub to authorized_keys2 directly. You will need to open authorized_keys2 and paste the id_rsa.pub from each client machine on it (or use the line below to append the content)

client-machine% cat ~/.ssh/id_rsa.pub | ssh user@target-machine \ 'cat >> .ssh/authorized_keys'

Now you can use ssh/scp without user/password information:

client-machine% ssh user@target-machine
client-machine% scp file user@target-machine:~/file

Take a look at the VisualCron automation suite. It has built in automation for SFTP and SSH as well as normal FTP.

If security is not a concern then the password can be in clear text in your script. E.g. on Microsoft Windows using pscp from the PuTTY package.

Example:

"d:\putty0.58\pscp" -pw MyNotSoSecretPassWord u:\outGoing\someFileToTransfer.7z kingOfTheHill@

Password: MyNotSoSecretPassWord. User name: kingOfTheHill. Host:

The sftp server in our case runs on a Linux based server.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like