I'm trying to copy a file to my local machine. While in the terminal of the remote server:

scp root@servername:filename.json ~/Desktop/

This returns:

/root/Desktop/: No such file or directory

So then I tried:

scp root@servername:filename.json ~/

which returned:

Permission denied (publickey).

ssh: connect to host 02 port 22: Invalid argument

Any idea what I can do to make this work? I am logged in as root user.

  • Permission denied (publickey). - use the correct key. Sep 29, 2020 at 9:54
  • 2
    Should ~/Desktop/ refer to your local machine? Then you should run the first command on your local machine instead of "in the terminal of the remote server". Sep 29, 2020 at 9:56

1 Answer 1


The scp command copies from its first argument(s) to its last. If you run scp root@servername:filename.json ~/Desktop/ in the remote terminal, you're telling scp to connect to the same server that you are already using and copy a file from there to the local destination directory ~/Desktop/. Remember that local in this instance is the machine on which you're running scp, i.e. the remote server, so it's roughly equivalent to cp ~root/filename.json ~/Desktop.

To copy a file to your local machine run it locally. Or if your local machine is accessible from the remote, invert the arguments and run it in the context of the remote server:

scp ~root/filename.json myUser@myLocal:Desktop/    # Might need sudo to read ~root files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .