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

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.


The problem may be the user name. I copied a file to my Amazon instance and first tried to use the command:

scp -r -i ../.ssh/Amazon_server_key_pair.pem ./empty.test [email protected]:~

and got the error:Permission denied (publickey).

I then realized that my instance is an Ubuntu environment and the user user is then "ubuntu" the correct command that worked for me is then:

scp -r -i ../.ssh/Amazon_server_key_pair.pem ./empty.test [email protected]:~

The file "empty.test" is a text file containing the text "testing ...". Replace the address of your virtual server with the correct address to your instance's Public DNS. I have replaced the ip to my instance with xx.yy.zz.tt.


I have to use ubuntu@ instead of ec2-user@ because when i ssh i was seeing ubuntu@ in my terminal, try changing to the name you see at your terminal

Also you have to set permission for pem file in your computer

chmod 400 /path/my-key-pair.pem

The below code will copy file from your computer to Ec2 instance.

scp -i ~/location_of_your_ec2_key_pair.pem ~/location_of_transfer_file/sample.txt ubuntu@ec2_your_ec2_instance.compute.amazonaws.com:~/folder_to_which_it_needs_to_be_copied

The below code will copy file from Ec2 instance to your computer

scp -i ~/location_of_your_ec2_key_pair.pem   ubuntu@ec2_your_ec2_instance.compute.amazonaws.com:~/location_of_transfer_file/sample.txt ~/folder_to_which_it_needs_to_be_copied