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
Related
I create ec2-instance on the AWS server:
Now I try to connect to the server with putty.
First of all, I downloaded the PPK for instance:
In the next I created a connection with putty:
After I launch connection and set the username as ec2-user:
in the result I got the error:
How to correctly connect to the ec2 instance with PPK?
What I understand from the question is that you did launch an EC2 instance successfully and afterwards you generated a new SSH key pair which does not have any connection to the already created EC2 instance.
What you should have done is to create a new key when the instance was launched:
OR select an existing key:
Now, the easiest way to solve this problem is to terminate the EC2 instance and recreate it with your existing key pair. You should be able to chose wlifter-ppk from the dropdown.
If, for some reason, you don't want to do this or it is not possible to terminate and relaunch the instance, there are several ways to rescue the instance and attach an existing SSH key.
I. Manually rescue the instance:
From Putty convert you .ppk to RSA public key.
Use EC2 Instance Connect or Session Manager to connect to your instance.
Locate the .ssh/authorized_keys file. For Amazon Linux instances this can be found in /home/ec2-user/.ssh folder.
Open authorized_keys, append the new RSA public key and save the file.
Connect to the instance using Putty.
II. Use EC2Rescue tool https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-boot-issues/
I assume you have local Windows and you'd like to connect to your EC2 AWS linux VM.
Use PuTTYgen to generate SSH-2 RSA key, 2048 bits.
Save keys into file, ie. myaws1.pub and myaws1.
In AWS dashboard, find your live instance, open up shell. It'll open up in the browser.
You will be logged in most likely as ec2-user
vi .ssh/authorized_keys
On your Windows, open up myaws1.pub file. take the relevant part and make it one line. Yes, it's broken up into multiple lines. Now press CTRL-C. And over in the browser where you Linux shell, press ESC-I (for insert), now CTRL-V (paste). Save and exit vi.
Back to Amazon Dashboard, in Network Security -> Security Groups, create SSH inbound rule with source 0.0.0.0/0
Now, when connecting to your instance from Putty use "Auth" in options.
This is what your new line in auth file should look like. I shortened it
ssh-rsa AAAAB3......... aws1
I am trying to connect to an EC2 instance with the key. But I get an error saying
No supported authentication methods available (the server sent: public key")
In the command window I get:
Using username "ec2-user"
Server refused our key
. Please help me
I will try to help! Suppose you are trying to connect using the PuTTY SSH client on your local machine. (Connecting with an FTP client like WinSCP is very similar).
Short answer: You need to let PuTTY know your ec2user IP address and associate the private key of the EC2 instance with the PuTTY session. On the AWS side you need to create a security group that allows inbound access from your IP address to your EC2 instance for SSH on port 22.
__
Long answer 😊:
Go to your EC2 page and click [CONNECT]
[]1
Copy the ec2User IP address to PuTTY.
When you created the EC2 instance, you were prompted to download the public/private key pair. You need that private key. If you don’t have that file, things are more complicated. (See Change key pair for ec2 instance).
But hopefully, you can find the private PuTTY Private Key file downloaded on your local machine:
Save the session. PuTTY should be all set up now.
Now on the AWS side, you need to make a new security Group:
Create the group and ADD an Inbound Rule:
Go back to EC2 and add security group to EC2.
In the dialog that pops up, check the security group that you just created for PuTTY remote access and click [Assign Security Groups]
Now give it a try!
I hope this works for you like it does for me.
ONE FINAL TIP: Make sure that you associate an Elastic IP address to the instance. Otherwise, this connection might stop working when someday you reboot your EC2. The elastic IP pins it down.
Verify that you are connecting with the appropriate user name for your AMI. Type the user name in User name in the PuTTY Configuration window.
The appropriate user names are as follows:
For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user.
For a CentOS AMI, the user name is centos.
For a Debian AMI, the user name is admin or root.
For a Fedora AMI, the user name is ec2-user or fedora.
For a RHEL AMI, the user name is ec2-user or root.
For a SUSE AMI, the user name is ec2-user or root.
For an Ubuntu AMI, the user name is ubuntu.
Otherwise, if ec2-user and root don't work, check with the AMI provider.
You should also verify that your private key (.pem) file has been correctly converted to the format recognized by PuTTY (.ppk).
My situation is that i can ping my EC2 instance using command shell of my PC but i cant connect to it using ssh (putty) ... i was able to do that this morning , was trying to send some files using scp , then i lost connection , i rebooted the instance many times but i still cant get access using ssh , i can still ping it tho .(i allowed all trafic in security group)
Thank you.
It seems when you rebooted, Your Server IP is changed. You copied new server IP in PING. Now For SSH you need to use same IP.
So Steps for SSH will be
Copy Public IP or use connect to instance option from EC2 Console.
Check which server you created(Ubuntu server username is ubuntu,while for amazon linux-ami is ec2-user)
Remember to launch your server in public subnet.
In case you have security group open to public, you should be able to SSH by above steps.
Thanks,
AB
I'm trying to use elastic beanstalk to deploy an application and one of the things I need to do is be able to log into the underlying ec2 instance and add dependencies. I added a key pair to the instance and put the private key file in ~/.ssh on my computer. Next I specified the key pair for the ec2 instance and it restarted and eventually the status was green
When I try to ssh into the ec2 instance I get the following error:
$ ssh ec2-user#myinstance.us-east-1.elasticbeanstalk.com
ec2-user#myinstance.us-east-1.elasticbeanstalk.com: Permission denied (publickey).
In the docs is says this could be due to an incorrect username.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html
Does anyone know what the default username is for ec2 instances created by elastic beanstalk?
Also if I'm doing this all wrong would appreciate some pointers there too.
1.To make sure that the there's no mistake the way you connect:
Go to EC2-> Instances
Select your instance
And press Connect
You should get the command to connect from the instructions from the Connect Popup. The correct username is mentioned there plus instructiins on how to set the correct permissions on the pem (applies to linux)
2.
Make sure that you modified the security group of the instance you're trying to connect do that it allows ssh from the ip of your pc. (This is not the case for the question, since the error is Permission denied (publickey), it means that it's not an sg issue, thx #diego)
3.
Also if you connect from a corporate network, try connecting from another network. It might be firewall issue.
4.
Last but not least make sure you ssh inside the .ssh path, or provide the correct pem path
I am having some issues with connecting to ubuntu instance in amazon. I can connect to the default instance with default AMI installation. But when I select ubuntu, I cannot ssh into it.
It says operation timeout. I have tried instantiating other instances rebooting changing key pairs etc.
ssh -i mykey.pem ubuntu#ec2-54-203-164-37.us-west-2.compute.amazonaws.com
ssh: connect to host ec2-54-203-164-37.us-west-2.compute.amazonaws.com port 22: Operation timed out
The strange thing when I stop the instance, then only the ssh command connects and says the are you sure you want to verify the fingerprint thing.
I can easily log into the micro instance with the default AMI installation
I have added the ssh port in the security group as well
Have you tried connecting via Putty ,just use a ppk file and please check once
also you can add ICMP to your Security Group and check for ping resposnses
Regards
Devashish