SCP with private key instead of password

snoopy76 asked:

I’m trying to move files via SCP in PHP. Since the SCP command prompts for a password — and I can’t seem to figure out how to use proc_open to pass parameters interactively — I’d like to explore the possibility of transferring files using a private key instead of using a password.

What exactly is the process for this that I may try to mimic it in PHP?

I answered:

If you have the password to log in to the remote server, you can certainly copy a key to it.

Login to the account on the source server and generate a keypair:

ssh-keygen -t dsa

Now copy the key to the destination server:

ssh-copy-id -i ~/.ssh/id_dsa user@remote

Done. Future logins will authenticate with the keypair and will not prompt for password.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.