Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 890
Amre Avatar asked Jul 03 '13 13:07

Amre


People also ask

How do I fix permission denied Publickey password or permission denied please try again?

If you want to use a password to access the SSH server, a solution for fixing the Permission denied error is to enable password login in the sshd_config file. In the file, find the PasswordAuthentication line and make sure it ends with yes . Find the ChallengeResponseAuthentication option and disable it by adding no .

Can I connect to EC2 instance Permission denied Publickey?

To solve the "Permission denied (publickey)" error when trying to SSH into an EC2 instance: Open your terminal in the directory where your private key is located and change its permissions to only be readable by the current user.

Why do I get permission denied Publickey?

Short description. "Permission denied (publickey)" and "Authentication failed, permission denied" errors occur if: You're trying to connect using the wrong user name for your AMI. The file permissions within the operating system are incorrect on the instance.

How do I transfer files to AWS EC2 instance?

Open a new command prompt and run the following command replacing the fields as needed: scp -P 2222 Source-File-Path user-fqdn @localhost: To copy the entire directory instead of a file, use scp -r before the path. This recursively copies all of the directory's contents to the destination EC2 instance.


2 Answers

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.

like image 162
brettwmc Avatar answered Oct 12 '22 23:10

brettwmc


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.

like image 45
Lars Silen Avatar answered Oct 13 '22 00:10

Lars Silen