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.
Related
Issue: Can't transfer files via FileZilla I get an error in the console saying "Permission Denied". I know why I am getting that error. I can't log in as a root user via SFTP because in the username field I have an ssh key that allows me to get into my Google Cloud Platform VM via FileZilla
Edit: What can I do to fix this issue or get around it?
You can refer to this documentation for "Permission denied" issues when uploading files to your vm thru SFTP.
Identify Error
Permission denied errors occur when you don’t have the required permissions to make changes to a file that you’re trying to edit over FTP.
Connect to VM Instance
Connect to your VM instance using the SSH (Linux Shell) terminal.
Check File Permissions
Execute the following command:
stat -c "%a %n" /path/to/file
Edit File Permissions
Run the following command:
sudo chmod 777 /path/to/file
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:~
I am able to connect to Amazon Ec2 instance but unable to ssh from my windows 10 machine to the Public ip. I am using command :
Attaching supportive screenshots:
1> Path of EC2Tutorial.pem:
2> Command for SSh:
Have followed some of the solutions given by people. chmod 400 EC2Tutorial.pem
also failed with error.
ssh -i EC2Tutorial.pem ec2-user#3.85.176.195
Resulted an error as below:
[ec2-user#ip-172-31-43-19 ~]$ ssh -i EC2Tutorial.pem ec2-user#3.85.176.195
Warning: Identity file EC2Tutorial.pem not accessible: No such file or directory .
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
I am following "Ultimate AWS Certified Developer Associate course on Udemy. and want to ssh the same way as suggested. not getting the same result. plz suggest.enter image description here:
Path to EC2Tutorial.pem file.
enter image description here
CHMOD 400 EC2Tutorial.pem
is a typical linux command to change the permission of the public key,so that it is no longer available for other users to access, in Windows I'm not sure if that is the best idea.
From windows it is recommended that you use an SSH Client like Putty(which is free to use) as that would help setup the configuration. You have to first install Puttygen and change the public *.pem file into a *.ppk file(which you can use in Putty to log in to the server.)
Here is a documentation on how to do that.
AWS Document Link for Using SSH with Putty
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.
I have Cygwin installed on Windows 7 and use it for SSHing into various machines.
I just created an AWS account and generated public/private keys for my free tier instance. I downloaded a PEM file (private key) and am now trying to SSH into the node with it. According to the AMIs docs, the AMI I am using doesn't use a password and 100% relies on SSH like so: ssh core#blah.example.com.
This means I need the PEM file "installed properly", but I'm not sure how to do this, especially on a Windows/Cygwin stack. Under ~/.ssh I see the following:
C:/Users/myuser/.ssh/
id_rsa
id_rsa.pub
known_hosts
I tried simply copying the PEM file into .ssh/ but that is not working. Any ideas?
I don't know if cygwin uses the same client as linux, but there are a number of things missing from your question. But I'll give you some suggestions.
What was the error message you got that leads you to believe that copying the file into .ssh isn't working? I'd guess that you need the right permissions on the .pem file - the .ssh directory should be 700, and the pem file should be 600. What does ls -la ~/.ssh look like? In any case, try:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*pem
Next, you have to make sure you log in with the right user:
ssh -i ~/.ssh/whatever.pem username#ec2-ip-or-hostname
The user name will be different depending on the AMI - for example, the Amazon Linux AMI uses ec2-user, while some older RedHat AMIs still use root, and I think ubuntu use ubuntu#
Finally, you have to make sure that the security group assigned to the instance have port 22 open to your IP address.