0

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

1

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.

  • First one states - /var/www/html/index.php: Not a directory. The public key shouldn't have changed, however I did try the ssh-keygen command, but I get the same errors. – Edward144 Sep 22 '17 at 11:11
  • Are you sure /var/www/html/ exists and is accessible by the user doing scp? – AdrianH Sep 22 '17 at 11:12
  • It does exist, and i'm logged in as root so there shouldn't be any issue – Edward144 Sep 22 '17 at 11:16
  • So, you're copying /var/www/html/index.html to /var/www/html/index.php? I'm asking because I didn't see a PHP file in the OP. Could it be that the source or destination contains a directory with the name index.html or index.php and SCP then tries to copy a directory? – AdrianH Sep 22 '17 at 11:23
  • 1
    Analysis of the first issue looks right - but the later errors are due to the OP specifying a ssh target as the local end rather than writing direct to the filesystem. On its own this wouldn't e a problem but by explicitly using a single p[rivate key, the client app is trying to use the private key for the remote server to authenticate against the local server. – symcbean Sep 22 '17 at 15:23
0

Basically you're missing the syntax in all the aspects. You should check syntax first. If I want to copy files from VPS to local server, I would do like below on local machine.

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

This would copy whole folder to my local /var/www/html/

Or If I am transferring data from my VPS to my local machine then I need to have a public IP to my local machine or server assigned. And from remote VPS I would do something like below.

cd /var/www/html/
scp -i <key_path> -r * root@<my_local_machine_public_ip:~/var/www/html/

OR Copy to /tmp folder on local machine from remote VPS like below.

cd /var/www/html/
scp -i <key_path> -r * root@<my_local_machine_public_ip:~/tmp/
-2

Add following options in the scp command

-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.