Ssh – SCP Unable to copy from server with Private Key

private-keyscpssh

I'm trying to use SCP to copy a file from a remote VPS which uses private keys to a local machine.

I'm getting different errors depending on what I try and I am not sure what the correct method should be.

Here is what I have tried:

scp -i ~/.ssh/private-key root@123.456.78.90:/var/www/html/index.html /var/www/html/

This asks for the private key password, then gives the error /var/www/html is a directory.

scp -i ~/.ssh/private-key root@123.456.78.90:/var/www/html/index.html root@localhost:/var/www/html/

This asks for the private key password, then says Host Key Verification Failed. lost connection.

scp -i ~/.ssh/private-key root@123.456.78.90:/var/www/html/index.html root@192.168.1.142:/var/www/html/

This simply gives a blank screen which seemingly lasts forever. I assume this might be the method that is actually working, but may just be copying incredibly slowly?

I have tried connecting to the server using ssh, with the same key file, which works fine, so I'm not sure what the issue is.

Does anyone have a solution, or knows what I am doing wrong? Thanks

Best Answer

For the first error - try giving the name of the file - as the error message says, instead of /var/www/html put the destination as /var/www/html/index.html.

The second error sounds like the server you're trying to copy from has changed its public key since last access. If that's the case (and you're sure it's not a security breach), use ssh-keygen -R host to remove the cached key; you will be asked to accept the new key on the next connection attempt. However, I think modifying the first way should work.