transferring a keypair to an ubuntu instance - amazon-web-services

I have added a new user to my instance. I would like to transfer the pem file to that account so I can complete the instructions of adding a user (https://aws.amazon.com/premiumsupport/knowledge-center/new-user-accounts-linux-instance/). I am in the section that details me creating a key pair and now I would like to transfer it from my computer to the new user account in my instance. Every time I do it, I get a timeout failure:
(ssh: connect to host ip-XXX-xxx-xxxx.compute-1.amazonaws.com port 22:
Operation timed out lost connection).
I am using below command to connect to the instance:
scp -i ~/.ssh/my.pem ~/Downloads/new.pem
ubuntu#ip-xx-xx-xxx.compute-1.amazonaws.com:~/directory/.
I already added port 22 with my ip as a rule and also chmod 400 new.pem and rebooted. Please help!

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

Lost access to EC2 instance

I reformatted my macbook and completely forgot to copy my ~/.ssh directory.
I tried ssh'ing into my EC2 instance
$ ssh ec2-user#xx.xxx.xxx.xx -i xxx.pem -v
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to xx.xxx.xxx.xx [xx.xxx.xxx.xx] port 22.
debug1: connect to address xx.xxx.xxx.xx port 22: Operation timed out
ssh: connect to host xx.xxx.xxx.xx port 22: Operation timed out
But I presume it's not working because my PEM file is linked to the id_rsa file on my old laptop?
I had the PEM file in my google drive.
I've tried
sudo chmod 400 xxx.pem
Update my security group to allow SSH access
to my new laptop
Any ideas how I can regain access to my EC2 insance?
I would generate a new key pair as explain here, but it requires me to have access to the instance
Update: check #jordanm comment. You have no connection to the instance, maybe there is no need to create a new one.
As far as I know there is only way to create a new one. You can keep data if you make an image of your existing instance. You may have changed external IP if your instance has no elastic IP attached.
Login to AWS Console
Create a new key pair.
Select your EC2 instance in the list, in the top-left corner select Actions -> Image and templates -> Create image. Fill the form to create an image.
Launch a new instance using the image you've created and your new key.
(optional) If everything is in place consider terminating the original instance using console.

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>

Cannot ssh to newly-launched instance in AWS

Several months ago, my friend decided to stop one of his instances. Before stopping it, he created an image of its used to launch it again in the future.
Today, I launch the new instance again from that image, but I cannot ssh into that new instance while I can still ssh into the his old instance. I use the same key pair and security group as the old instance.
The error is: ssh: connect to host xxx.xxx.xxx.xxx port 22: Connection refused
What are the possible causes and how can I fix them?
Connection refused indicates a network failure when trying to ssh. You shuold make sure your server contains a security group allowing your IP to connect to the server via port 22.
You can resolve the issue by adjusting the permissions of "/var/empty/sshd":
chown root:root /var/empty/sshd
chmod 711 /var/empty/sshd
If it does not solve your issue please share the output of telnet.

Issues with connecting to ubuntu instance in amazon ec2

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