SSH into the EC2 instance on Windows is not working - amazon-web-services

I am trying to SSH into my AWS EC2 instance. I am not using putty. I am using Virtual Environment and python SDK instead. So before I SSH into the server, I need to activate the virtual environment. But it is not working as I expected. This is what I have done so far.
I activated the virtual environment running the following command.
~\eb-ve\Scripts\activate
It was activated. Then I downloaded the SSH Key in pem format which is attached to my EC2 server. After I have download, the file I changed the permission of the file as follow.
chmod 0400 ForkProd.pem
Then I tried to SSH into the server running the following command.
ssh -i "ForkProd.pem" root#ec2-13-229-232-13.ap-southeast-1.compute.amazonaws.com
Then I got the following error.
Permissions for 'ForkProd.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "ForkProd.pem": bad permissions
root#ec2-13-229-232-13.ap-southeast-1.compute.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
I remember I did the same to the other project before and it worked. I am not sure what went wrong this time. What is wrong with the configuration and how can I fix it?

I've definitely had this issue in the past on Windows machines. If I remember correctly and your permissions on the key all check out, then it might be something to do with the .pem key being in your home directory or the root.
If you move the .pem into a less 'global' folder e.g. C:\Users\your-username\Documents\ForkProd.pem you may have better luck.
edit: +1 for the link from jarmod in the comments above

Related

Unable to SSH to Amazon Linux instance from windows 10.I have kept my EC2Tutorial.pem on my desktop. Plz Suggest

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

Permission denied when connection to ec2 intance, i have given the file permisson 400, but still not working

I have created an ec2-intance on AWS. But when im trying to connect to it by using my .pem file, im getting error message: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). I have changed the permission to this file by chmod 400 myfile.pm.
This is the command i use to connect to my instance: ssh -i ec2demo.pem ec2demo#ec2-35-158-140-25.eu-central-1.compute.amazonaws.com
I also searched for the issue on internet, and some people say i need to type chmod 600 myfile.pem. It still not works. Im using macOS Mojave, and the ssh client integrated. Do i need to install the AWS-CLI to make it works? Or should it work without AWS-CLI? And is it better to use ssh client from homebrew, or?
Thanx for help
When launching a new Amazon Linux instance on Amazon EC2, the public half of the keypair is copied to:
/users/ec2-user/.ssh/authorized_keys
You can then login to the instance using the private half of the keypair:
ssh -i key.pem ec2-user#1.2.3.4
(Or, you can use a DNS name instead of an IP address.)
It sounds like you have not logged into this instance yet, so make sure you login as ec2-user instead of ec2demo. The name of the instance does not impact the Linux user on the instance.

unable to ssh the ubuntu EC2 instance on macOS - Permission denied(Public Key)

I am unable to SSH to the Ubuntu EC2 instance on AWS from macOS terminal.
Tried the following cmd from the terminal :
ssh ubuntu#ec2-13-127-143-37.ap-south-1.compute.amazonaws.com
And
ssh 13.127.143.37#ec2-13-127-143-37.ap-south-1.compute.amazonaws.com
both are giving the same error: Permission denied (publickey).
I tried generating the public key using ssh-keygen and imported it under the key pair options on AWS, but still getting the same error.
Please help me with this.
Thanks,
Nidhi Arora
The command in terminal should be something along the lines of:
ssh -i /path/to/yourkey.pem username#10.0.0.1
Don't forget too you need specific permissions on "yourkey.pem" - chmod 400 yourkey.pem - Reference to answer here
You aren't providing the private key when you establish the connection. You can download your private key when you launch the instance. Navigate to the folder where your private key is saved and run the following command. This is to ensure your private key is not publicly viewable. SSH will not work without this.
chmod 400 private-key.pem
Your final command should look something like this
ssh -i "private-key.pem" ec2-user#ec2-13-127-143-37.ap-south-1.compute.amazonaws.com
On the pane listing your EC2 instances, if you select your instance, the 'Connect' button will get activated. If you click on that, it will give you the connection instructions specific to your instance. Attached screenshot of the button below.

how to change the permission of PEM file in ec2-instance?

I created an ec2-instance with amazon-linux as my OS. I use to connect to the instance using PUTTY. everything was fine. now i changed the permission of some files in the instance to 0777 using chmod command. by mistake the permission of .pem file in the instance also got changed and i'm not able to connect the insatnce . getting error like Permission denied (public key).Is there any way to change the permission of .pem file in the ec2-instance ?
If you cant log in with the root user, nor any other user who could then elevate their privileges to root, you've probably bricked the machine. I dont believe, for example, Amazon will even retain a backdoor into the VM.

Configuring AWS SSH keys on Windows/Cygwin

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.