SSH connection to EC2 instance fails - amazon-web-services

I'm trying to create the SSH connection to EC2 instance but getting the error message that the keypair file does not exist.
AWS Management Console confirms that the keypair file exists:
Making connection to EC2 instance is fine but its seems that there aren't any files:
AWS Management Console confirms that the right command to set permissions is:
chmod 400 tauno537_aws_keypair.pem
When trying to execute this, it gives the following error message:
chmod: cannot access ‘tauno537_aws_keypair.pem’: No such file or directory
When trying to create the SSH connection to EC2 instance, it gives the following error message:
ssh ec2-user#x.xxx.xxx.xxx -i tauno537_aws_keypair.pem
Warning: Identity file tauno537_aws_keypair.pem not accessible: No such file or directory.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
What I have done wrong? Is it correct that when...
Making connection to EC2 instance (PuTTY login), the private key needs to be used?
Creating SSH connection, the public key needs to be used?
What's the diference between PuTTY login and SSH connection at all? Doesn't they both mean that making the connection to the EC2 instance?

Both your errors point to the fact that the private key file is not found in the directory where you're running from/pointing the private key to
Putty is just a SSH/Telnet client, so ultimately you are using a SSH connection. When a keypair is created, the private key remains clientside and the public key is uploaded to the server

Related

Cannot connect to EC2 Instance either SSH or EC2 Instance

I got stuck when connecting to my EC2 instance. I did try both SSH with .pem file or EC2 Instance Connect. Everything was ok in the first time. But after that, something went wrong.
I tried to terminate my instance and launch new one once. But the new instance get this error too. Too weird.
This is error text when connecting via EC2 Instance Connect.
And this is log when connecting via SSH with verbose
And this is the security rules for my instance
Does anyone know solution for this case? Thank in advance.
-- UPDATE 1--
Result after run Reachability Analyzer with source (gateway) and destination (instance)
yes, all problems in ssh is in the user name inside of the instance, So follow these steps to solve your problem:
go to ec2 dashboard and check what is the user name inside your
instance.
make new connect with instance and download new file ".pem" from
ec2 dashboard.
make new file and named it "config" in local machine with this
path :
~/.ssh/config
write this code below in your config file
# Enter the alias of the ECS instance to connect to the instance by using an SSH key pair.
Host ec2
#Enter the public IP address of the instance.
HostName <public IP>
#Enter the port number. The default port number is 22.
Port 22
#Enter the logon account.
User <put the user name you found in your instance>
#Enter the address of the .pem private key file on your PC.
IdentityFile <~/Desktop/myservice.pem>
if you want to ssh it just do like this
ssh ec2

ElasticBeanstalk "eb ssh" throwing errors: "Host key verification failed."

I am trying to SSH into my EC2 instances of my ElasticBeanstalk environment. I could SSH into the instance. Then I terminated the instance and pinned up the new instance. Then it broke when I tried to SSH again. This I what I have done so far.
I created an SSH KeyPair in the AWS console named MyanEatSSH.
Then I set up the SSH running the following command.
eb ssh --setup
I selected the Key name I created.
Then I downloaded the key and put it under ~/.ssh/ folder.
I could ssh into the EC2 machine running the following command.
eb ssh
It was working as expected. The problem began when I deleted the instance in the EC2 console. I deleted an EC2 instance. Then, the Beanstalk spin up the new instance since it has the health check and Auto Scaling capability.
Then I ssh again into the new instance. This time, I got the following error.
###########################################################
# WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! #
###########################################################
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:enloOGgT3a/TLEoeibCGEbAmDogbpqHZWdy8qP5WyEE.
Please contact your system administrator.
Add correct host key in /Users/wai/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/wai/.ssh/known_hosts:35
ECDSA host key for {ip} has changed and you have requested strict checking.
Host key verification failed.
As an attempt to fix it, I tried setting up the SSH running this command again,
eb ssh --setup
It still does not work. I tried to create a new SSH Key and tried setting it up again. It does not work too. It is throwing the same error. What is wrong and how can I fix it?
When you reinstall the server or associate elastic IP with new launch server of previous instance its identity changes, and you'll start to get this message.
Simply remove the key from known_hosts by deleting the relevant entry
ssh-keygen -R <IP>

Permission denied (publickey) error while copying to EC2

I'm trying to copy file from my local to Aws EC1 or EC2.
my detailed setup.
Created two EC2 instances.
Got .pem file (Private key) from AWS consle.
Generated private key from .pem file (step2).
Able to connect EC1 and EC2 using private key generated in step 3.
Copied .pem file in EC1 and EC2 servers, by doing that am able to copy files in between EC1 and 2 aws servers.
Now I want to copy the file from my local machine to AWS EC1 and EC2 serves.
But when am trying to do below command (using public DNS):
ssh ubuntu#ec2-18-222-170-204.us-east-2.compute.amazonaws.com
getting below error
Permission denied (publickey)
And when I do it using Private DNS:
ssh ubuntu#ip-172-31-43-162.us-east-2.compute.internal
getting below error:
ssh: Could not resolve hostname ip-172-31-43-162.us-east-2.compute.internal: Name or service not known
what should I do to fix this or make it work?
Output
OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "ip-172-31-43-162.us-east-2.compute.internal" port 22
ssh: Could not resolve hostname ip-172-31-43-162.us-east-2.compute.internal: Name or service not known
First thing, ssh ubuntu#ip-172-31-43-162.us-east-2.compute.internal this will only work within VPC, as its private IP and your local system will never able to resolve this DNS until you connect with some VPN from that VPC.
It's not a security group issue, your instance is reachable.
You should post debugs log for ssh ubuntu#ec2-18-222-170-204.us-east-2.compute.amazonaws.com, you can get debug log using ssh -v ubuntu#ec2-18-222-170-204.us-east-2.compute.amazonaws.com
But I am sure it's not picking the pem file from right location. Two possible reason
set chmod 400 your.pem and then try to connect
specify the key in your ssh command
ssh -i path_to_key/private.pem ubuntu#ec2-18-222-170-204.us-east-2.compute.amazonaws.com
Might be possible user ubuntu not exist in that case you can try with root and AWS will return the user which can ssh to that server.
You can also get ssh command for AWS ec2 console. -> Select Instance and click connect, copy the command and try to connect.

Trying to connect to RDS instance through my ec2 instance from my local machine and coming up with the following error

Tried connecting to the rds instance through the ec2 instance from and my local machine coming up with an error saying "Permission denied (public key)"
ssh -L 3306:db_instance_name.cxtitvmupc3w.us-west-2.rds.amazonaws.com:3306 my_instance_ip
Permission denied(public key)
This is ssh saying that you have not provided a private key to establish the ssh session.
You would normally include -i keyfile.pem in the command, exactly the same way you would normally ssh to the instance.

Cannot create an SSH tunnel to Zeppelin web display on aws, using Putty on windows

The following instructions are given for the ec2 instance that I'm trying to connect to:
To access your instance: Open an SSH client. (find out how to connect
using PuTTY)
CHECK!
Locate your private key file (keypair.pem). The wizard automatically
detects the key you used to launch the instance.
I launched Putty with a .ppk and I also still have the .pem sitting on my local machine. However, how does this help once I am in the aws Linux terminal?
It sounds to me that the .pem should now be located on the remote machine, not my local one.
Your key must not be publicly viewable for SSH to work. Use this
command if needed: chmod 400 keypair.pem
This is fine once the previous step is clearer.
Connect to your instance using its Public DNS:
ec2-xxxxxxxxxxxxx.eu-west-1.compute.amazonaws.com
Example: ssh -i "keypair.pem"
root#ec2-xxxxxxxxxxxxx.eu-west-1.compute.amazonaws.com
I am currently typing this in (also trying ec2-user instead of root) but I get the following:
Warning: Identity file keypair.pem not accessible: No such file or directory.
Permission denied (publickey).
Please note that in most cases the username above will be correct,
however please ensure that you read your AMI usage instructions to
ensure that the AMI owner has not changed the default AMI username.
In case this is important, what user name are they referring to here?
I have also made sure the I can SSH into the security group from all locations.
Christopher, I am not sure if you have access to the AWS console, but If you do, then it will be easy to find out the correct user name of your EC2 machine. click on the check mark box to pick your instance, then click Connect, and it will show you the correct user name. If it is an amazon AMI image, it will most likely be ec2-user, other images can have root, ubuntu, bitnami, or any other user configured by the AMI creator.
Your error message: " Warning: Identity file keypair.pem not accessible" indicates an issue with your private key not being accessible.
You said you converted the .pem to ppk for putty, which will enable you to SSH via putty. If you need to SSH from an EC2 machine to another EC2 machine, you will need that private key with the "pem" extension.
Think of your private key as your password, except that it's stored in a file.
ssh -i "keypair.pem" root#ec2-xxxxxxxxxxxxx.eu-west-1.compute.amazonaws.com
This command says: Log me in via SSH protocol to server xxxx.eu... using password file (Private key) "keypair.pem" that resides in the current directory.
if you do an "ls" and you don't see "keypair.pem" then that is your issue.
I hope that helps!