I can login to the remote server via ssh and navigate through it's file system, but as soon as I try to scp a file from the server to my laptop I get an error message.
Example:
user@server:/file$ scp -r user@server: /file/ /My/Home/Dir [I Hit Enter]
Permission denied (publickey)Why am I getting this error, and how can I resolve this.
Thanks
3 Answers
Your server doesn't have a private key to access to your laptop. The relationship is only one-way.
You'll need to create a key on your server and add its public key to your laptop. Here's a basic outline:
- SSH in to your server
- run
ssh-keygento generate a key - copy the generated public key to your laptop.
- You should now be able to SSH back in to your laptop.
Rather than using SCP to push a file from the server, to your laptop. Why not try using SCP on your laptop to pull a file from the server? This would mean you wouldn't need to setup an an SSH server on your laptop, or configure public key authentication for your server. The SCP command you initially posted intends to do this. You simply ran it from the wrong place.
Rather than executing this command from within your SSH session on the server, run it from a terminal window on your laptop.
I had the same trouble. My fault was, that I forgot to add my private key to the ssh-agent after I reformatted my partition. If you have the same issue, fix it by:
$ ssh-add /path_to_your_private_key