Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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.

share|improve this question
The command you are running above seems to be while on the server, copying a file via scp from the server itself to the server. You need to run scp from your laptop, not from the server. – Paul May 22 '12 at 0:18
the command should be something like 'scp -r /file user@laptop:~/' – emgee May 22 '12 at 0:28
@emgee That assumes that the laptop is running an ssh server, which isn't indicated yet. – Paul May 22 '12 at 0:32
I'm running OSX lion connecting to an Ubuntu server. I don't believe I am set up as a server – Daniel Toebe May 22 '12 at 0:47
@Paul excellent point. DanielToebe, System Preferences -> Sharing -> Remote Login should be enabled for you to be able to scp to a OS X laptop – emgee May 22 '12 at 1:05

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:

  1. SSH in to your server
  2. run ssh-keygen to generate a key
  3. copy the generated public key to your laptop.
  4. You should now be able to SSH back in to your laptop.
share|improve this answer
can I do that from my laptop – Daniel Toebe May 22 '12 at 0:07

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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