scp to EC2 Permission denied (publickey) but ssh works - amazon-web-services

I can ssh to my ubuntu AWS EC2 instance but can't do scp to file transfer
I am using below command at my mac
sudo scp - i file.pem /Users/me/proposal.pdf ubuntu#ec2-IP.compute-1.amazonaws.com:/mnt/projectFolder/
And I am seeing error ubuntu#ec2-IP.compute-1.amazonaws.com Permission denied (publickey) Lost connection
What I have tried:
Followed this link and tried Beau's answer
Made sure my .pem file has 400 permission
Made sure my authorized_keys file in .sshd folder has my .pem file as authorized
What am I missing?

Looks like a typo in your command. The command should be (note the -i):
sudo scp -i file.pem /Users/me/proposal.pdf ubuntu#ec2-IP.compute-1.amazonaws.com:/mnt/projectFolder/

I had a similar problem that was caused by the EC2 instance having no read/execute permissions to /usr/bin/scp.
$ ls -l /usr/bin/scp
---------- 1 root root 133720 Nov 23 07:38 /usr/bin/scp
Issue was solved by running sudo chmod 755 /usr/bin/scp
I know this was not the problem that OP had but future searches may bring up this question and help someone else.

Related

scp from local computer to EC2 instance (with WSL) - Permission denied (publickey)

I am following this guidance and try to copy a simple code from local directory into EC2 instance.
Up to and incl. section Connect to your Linux instance using WSL, everything works as in the AWS guidance. But when I try to copy a python file from local computer into the EC2 instance using the code below,
sudo mkdir WSL-path
cd WSL-path
sudo cp /mnt/c/.../test-pair2.pem test-pair2.pem
sudo cp /mnt/c/.../hello_world.py hello_world.py
sudo chmod -R 400 test-pair2.pem
scp -i test-pair2.pem hello_world.py ec2-user#ec2-18-184-76-175.eu-central-1.compute.amazonaws.com:~
I cannot connect to the instance and get the following:
Load key "test-pair2.pem": Permission denied
Permission denied (publickey).
lost connection
The key in the local instance can be only read by the user, with the default I could not even connect to EC2. But otherwise I think I am following the AWS manual. Would much appreciate explanation what I am doing wrong.
If you have permission denied check the following factors:
Is the key you're using using permissions 400. To check run ls -lah test-pair2.pem. If not fix it by using chmod 400.
Is the owner of the file you, if not run chown $USERNAME test-pair2.pem.
As it works with sudo we know that the host is the issue, not the target.
So problem solved - silly mistake - adding SUDO works:
sudo scp -i test-pair2.pem hello_world.py ec2-user#ec2-18-184-76-175.eu-central-1.compute.amazonaws.com:~

AWS SCP Directory Transfer getting "Permission denied (publickey)"

I am trying to scp a folder from my local computer to an amazon ec2 instance running ubuntu.
I am running windows so I am using cygwin to SCP the folder, from looking around on the internet, I was directed to only install the openssh package, so I downloaded all of the packages with that name.
In this case, I have the .pem file and folder I want to scp on my desktop
I have this as the working directory open on cygwin
"User"#"User"-PC /cygdrive/c/users/"user"/desktop
Then I type this
scp -r -i key.pem foldername ec2-ubuntu#"dns".amazonaws.com:~
And after I say "yes" I am shown
ec2-ubuntu#"dns".amazonaws.com: Permission denied (publickey).
Any help would be greatly appreciated.

How to copy files with scp to an ec2 instace?

i am trying to copy files to an EC2 instance with the scp command as follows:
scp -i "key-pair-name.pem" somefile.txt ec2xxxx.us-west-2.compute.amazonaws.com:~
I get the following error:
Permission denied (publickey).
lost connection
I am using an amazon linux machine
I am able to ssh just fine.
I've gone over Q&A here, with no luck.
Try specifying the username, eg:
scp -i "key-pair-name.pem" somefile.txt user#ec2xxxx.us-west-2.compute.amazonaws.com:~

permission denied to transfer file from my computer to EC2 with scp command

The instance is launched and I can connect perfectly from my computer. However when I am trying to upload a file to ec2 using the following command:
scp -r -i key.pem path/file ec2-54-195-205-200.eu-west-1.compute.amazonaws.com:/media/ephemeral0/
I have always the following error:
Permission denied (publickey).
lost connection
The username seems to be missing in your scp command. Try adding it before the remote host, separated by a #. For example, with username admin:
scp -r -i key.pem path/file admin#ec2-54-195-205-200.eu-west-1.compute.amazonaws.com:/media/ephemeral0/
The default username in EC2 varies depending on the OS. See this answer for some hints.

couldn't get root access to aws ec2

I'm trying to access aws instance using ssh with private keys downloaded from aws.
I got access using ec2-user which their documentation suggested.
$ ssh -i upd_prayag.pem ec2-user#ec2-54-209-155-100.compute-1.amazonaws.com
Apparently, I find two users there,
ec2-user
prayagupd
What I want is ls the user prayagupd to check whether the directory I have cloned from github exists there.
Unfortunately I see permission denied message on that user.
I get Permission denied (publickey) on
$ sudo ssh -i upd_prayag.pem ec2-user#ec2-54-209-155-100.compute-1.amazonaws.com
They suggest sudo su - should work but it has been asking password, some of the links I found through google is making me anxious that I can't get root access.
Reference
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
If the instance is created from an AWS image, then you cannot get root access.