Permission Denied Error when using scp to copy a file to Amazon EC2 instance from Mac OS

Steve K

I have read several StackOverflow articles on this problem and googled other sources with no luck. I've checked AWS documentation and can't resolve the issue. I have been working on this for several hours and am really stuck.

I've found articles referring to similar problems but the issue looks to always be a typo or mistake on the user's part. In my case, I'm confident I have ensured there are no typos or errors in what I'm doing.

I'm using Mac OS X Yosemite to connect to my AWS EC2 instance. I cannot scp files from my local machine to my instance, but I have been able to in the past, I believe before I upgraded to Yosemite (although I'm not 100% certain about before or after the upgrade). Regardless, I'm now getting a permission denied error.

I am able to ssh just fine into my instance. I do so like this:

ssh -i mykey.pem [email protected]

Everything works fine with the ssh. But when I attempt scp like this:

scp —i mykey.pem ~/Sites/test.html [email protected]:/var/www/html/

I get the following error:

Permission denied (publickey). lost connection

I've been trying this for hours and have confirmed the following:

  1. I CAN ssh in just fine.

  2. My .pem file has 400 permissions and is not viewable to the world.

  3. I have correct permissions and ownership in the /var/www and /var/www/html folders

    (I went through the amazon setup tutorial again and ensured I used all permission settings as they described. My user is part of the group with access to those folders.

When I run the scp -v command I can see that scp does not appear to be even trying to use the specified Identity file. I get the following output:

(Notice the program being executed has dropped the -i from the scp command)

Executing: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myEC2host.myzone.compute.amazonaws.com [public AWS ip] port 22.
debug1: Connection established.
debug1: identity file /Users/myusername/.ssh/id_rsa type -1
debug1: identity file /Users/myusername/.ssh/id_rsa-cert type -1
debug1: identity file /Users/myusername/.ssh/id_dsa type -1
debug1: identity file /Users/myusername/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA  {some hex output}
debug1: Host 'myEC2host.myzone.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/myusername/.ssh/id_rsa
debug1: Trying private key: /Users/myusername/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection

However, when I run ssh -v I get the following output which DOES immediately use the correct Identify file:

ssh -v -i mykey [email protected]
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to myEC2host.myzone.compute.amazonaws.com [54.69.211.59] port 22.
debug1: Connection established.
debug1: identity file mykey.pem type -1
debug1: identity file mykey.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA {some hex output}
debug1: Host 'myEC2host.myzone.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: mike.pem
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to myEC2host.myzone.compute.amazonaws.com ([myEC2IP]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_CA.UTF-8

I'm not sure what else to try or how I might be able to resolve this. I'm hoping somebody will have the same environment and can confirm the issue or supply a resolution.

Thanks in advance!

Kenster
scp —i mykey.pem ~/Sites/test.html [email protected]:/var/www/html/
Executing: program /usr/bin/ssh host myEC2host.myzone.compute.amazonaws.com, user ec2-user, command scp -v -d -t /var/www/html/

The dash in your scp —i... command is a unicode EM dash, not an ASCII dash. Scp isn't interpreting it as a command-line option.

In fact it interpreted "—i", "mykey.pem", and "~/Sites/test.html" as three files to be copied. You can tell this because scp added "-d" to the command line for the remote scp instance. The "-d" flag tells the remote scp instance that the target has to be a directory. scp adds that flag to the remote command when it's copying more than one file, but not for copying a single file.

Maybe you copied the scp command from a word processing document? Microsoft Word is notorious for changing dashes and quote marks to typesetting versions. It's something to be careful about.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

permission denied when cloning from GitLab repo hosted on an Amazon EC2 instance

From Java

Permission denied (publickey) when SSH Access to Amazon EC2 instance

From Dev

Amazon EC2 instance "Permission denied (publickey)"

From Dev

Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance

From Dev

Permission denied (publickey) when pushing commit to amazon ec2

From Java

Trying to SSH into an Amazon Ec2 instance - permission error

From Dev

"Permission denied (publickey)" error when ssh'ing to Amazon EC2 Debian AMI 05f3ef71

From Dev

Connecting to Amazon EC2 Instance on Windows 10 bash - Permission denied (publickey)

From Dev

When i trying to copy folder from amazon ec2 to s3 .I got an error

From Dev

Permission denied to connect to Amazon EC2 using SSH at Windows 8

From Dev

"No such file or directory" error when attempting to copy (using scp) from remote host to local machine

From Dev

"No such file or directory" error when scp from remote to local instance

From Dev

Permission denied (publickey) when connecting to EC2 via SSH on Mac Mavericks

From Dev

permission error to SSH EC2 instance

From Dev

/etc/profile: Permission denied after restarting Amazon EC2

From Dev

Can't scp file from local to remote host - Permission denied

From Java

scp (secure copy) to ec2 instance without password

From Dev

Unable to connect to AWS EC2 instance (Permission denied publickey)

From Dev

Permission Denied Error when downloading a file

From Dev

Rsync to Amazon Linux EC2 instance - Permission deniend

From Dev

using scp to transfer files in amazon ec2

From Dev

Android Studio IDE on Mac os:error=13, Permission denied

From Dev

Error when download a file from server using scp

From Dev

Adding a line into the hosts file, getting permission denied when using sudo - Mac

From Dev

Cannot SCP from Linux EC2 Instance to Local Machine

From Dev

Cannot SCP from Linux EC2 Instance to Local Machine

From Dev

scp copy over ssh doesn't work - permission denied error, please?

From Java

How can I confirm SSH fingerprint when connecting to a new Amazon EC2 instance using PuTTY?

From Dev

`cp` permission denied when copy a file owned by `root`

Related Related

  1. 1

    permission denied when cloning from GitLab repo hosted on an Amazon EC2 instance

  2. 2

    Permission denied (publickey) when SSH Access to Amazon EC2 instance

  3. 3

    Amazon EC2 instance "Permission denied (publickey)"

  4. 4

    Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance

  5. 5

    Permission denied (publickey) when pushing commit to amazon ec2

  6. 6

    Trying to SSH into an Amazon Ec2 instance - permission error

  7. 7

    "Permission denied (publickey)" error when ssh'ing to Amazon EC2 Debian AMI 05f3ef71

  8. 8

    Connecting to Amazon EC2 Instance on Windows 10 bash - Permission denied (publickey)

  9. 9

    When i trying to copy folder from amazon ec2 to s3 .I got an error

  10. 10

    Permission denied to connect to Amazon EC2 using SSH at Windows 8

  11. 11

    "No such file or directory" error when attempting to copy (using scp) from remote host to local machine

  12. 12

    "No such file or directory" error when scp from remote to local instance

  13. 13

    Permission denied (publickey) when connecting to EC2 via SSH on Mac Mavericks

  14. 14

    permission error to SSH EC2 instance

  15. 15

    /etc/profile: Permission denied after restarting Amazon EC2

  16. 16

    Can't scp file from local to remote host - Permission denied

  17. 17

    scp (secure copy) to ec2 instance without password

  18. 18

    Unable to connect to AWS EC2 instance (Permission denied publickey)

  19. 19

    Permission Denied Error when downloading a file

  20. 20

    Rsync to Amazon Linux EC2 instance - Permission deniend

  21. 21

    using scp to transfer files in amazon ec2

  22. 22

    Android Studio IDE on Mac os:error=13, Permission denied

  23. 23

    Error when download a file from server using scp

  24. 24

    Adding a line into the hosts file, getting permission denied when using sudo - Mac

  25. 25

    Cannot SCP from Linux EC2 Instance to Local Machine

  26. 26

    Cannot SCP from Linux EC2 Instance to Local Machine

  27. 27

    scp copy over ssh doesn't work - permission denied error, please?

  28. 28

    How can I confirm SSH fingerprint when connecting to a new Amazon EC2 instance using PuTTY?

  29. 29

    `cp` permission denied when copy a file owned by `root`

HotTag

Archive