Transferring a file to an amazon ec2 instance using scp always gives me permission denied (publickey,gssapi-with-mic)

Amre picture Amre · Jul 3, 2013 · Viewed 34.2k times · Source

I am trying to transfer a file to an ec2 instance. I followed the Amazon's documentation, this is what my command looked like:

scp -i [the key's location] Documents/[the file's location] ec2-user@[public dns]:[home/[destination]]

where I replaced all the variables with the proper things, I am sure it's the correct key and it has permission 400. When I call the command, it tells me the RSA key fingerprint, asks me if I want to continue connecting. I type yes and it replies with

Permission denied (publickey,gssapi-with-mic)
lost connection

I have looked at many of the other similar questions on stack overflow and can't find a correct way to do it.

Also ssh traffic is enabled on port 22.

Answer

brettwmc picture brettwmc · Jul 3, 2013

The example amazon provided is correct. It sounds like a folder permissions issue. If you created the folder you are trying to copy to with another user or another user created it, chances are you don't have permissions to copy to it or edit it.

If you have sudo abilities, you can try opening access for yourself. Though not recommended to be left this way, you could try this command:

sudo chmod 777 /folderlocation

That gives complete read/write/executable permissions to anyone (hence why you shouldn't leave it at 777) but it will give you the chance to test your scp command to rule out permissions.

Afterwards if you aren't familiar with permissions, I suggest you read up on it. this is an example: http://www.tuxfiles.org/linuxhelp/filepermissions.html It is generally suggested you lock down the folder as much as possible depending on the type of information held within.

If that was not the cause some other things you might want to check:

  • are you in the directory of your key when executing the 'scp -i keyname' command?
  • do you have permissions to use the folder you are transferring from?

Best of luck.