问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/65721493/lost-access-to-ec2-instance