I've searched all around and can't seem to find this... I'm trying to copy a private key to my local machine which is a Mac.

When I fire up terminal on my mac, I get Jamies-iMac:~ jamie$

So after I ssh into my Ubuntu server I tried

scp /path/to/myfile.txt jamie@Jamies-iMac:/path/to/myfile.txt

which gives me:

ssh: Could not resolve hostname Jamies-iMac: Name or service not known
lost connection

In place of jamie@Jamies-iMac:/path/to/myfile.txt I've tried some other variations but nothing seems to work. Thanks for your help.


@ovc had it right, but there is a syntax error, and my edit got rejected for some reason. You need to have a colon between the user and filepath on the ubuntu side, and on the mac side you need to have the /Users/username/ portion in the filepath. Like so:

scp username@ /Users/Jamie/local/path/to/myfile.txt

This assumes you have private key authentication set up.

  • 3
    Its showing "Permission Denied (public key)" – Anooj Krishnan G May 12 '15 at 13:14
  • default port is 22, -P to specify port – Vahid Feb 13 '17 at 5:02
  • 2
    Use -r to recursively copy a folder – speckledcarp Mar 21 '17 at 15:02

You're doing it the wrong way around. Simply use the scp command on the Mac, like this: scp username@ /local/path/to/myfile.txt. You may also just use FileZilla which is a graphical client. Connect to your Ubuntu with a URL like sftp://, of course you need to use the valid IP address.

  • Ah, so I can only go one way. I knew it was something simple. Thanks. – inorganik Jun 25 '13 at 20:40
  • I made a small edit to your answer, it didn't work until I did it the way that is shown in the edit. – inorganik Jun 25 '13 at 23:00
  • 1
    inorganik, it can go both ways long as you have an SSH server running on both machines. I don't beleive that's the case with Macs, though. Otherwise, you'll need to use scp from the machine without the server so that it can perform a connection. – ooa Jun 26 '13 at 20:17
  • +1 for mentioning the graphical client option, I used Cyberduck and it worked a treat. – Dorian Farrimond Jun 3 '19 at 19:48

Excellent answers above. Additionally, if you need to use a certificate for authentication, you can use the -i flag.

scp -i /path/to/cert username@ /Users/Jamie/local/path/to/myfile.txt
  • I didn't see your reply earlier, but this was what I needed. I kind of deduced it from the answer above and then saw yours. Thank you – AJC Aug 23 '18 at 21:26

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.