Skip to content

How i can connect again to my instance?

0

I'd made a big mistake today while i tried to make my ubuntu server more safe.

With ufw tools i'd denied the ssh access to all ipv4 adresses except my ip (or at least that's what I thought). In the network tab on lightsail web console, the firewall allows any ipv4 but it didn't work. Now i'm unnable to connect with windows cmd/pem key and lightsail ssh console. 😥

How i can recovery the access again?

I don't have any backup or snapshot. And this is my job project.

SSH console

2 Answers
1

Hello.

Please try restoring your instance by following the steps in "An OS-level firewall is blocking SSH port access" in the following document.
Create a snapshot from your existing Lightsail instance, and when restoring from that snapshot, configure a launch script to disable ufw.
https://repost.aws/knowledge-center/lightsail-resolve-ssh-console-errors

sudo ufw disable
sudo iptables -F
sudo mv /etc/hosts.deny /etc/hosts.deny_backup
sudo touch /etc/hosts.deny
sudo systemctl enable sshd
sudo systemctl restart sshd
EXPERT

answered a year ago

AWS
EXPERT

reviewed a year ago

0

Step 1: Create a temporary recovery instance Go to Lightsail Console. Launch a new instance with the same OS as your original one (Ubuntu). Wait for it to be ready, then SSH into this temporary instance via web or PuTTY.

Step 2: Attach your original disk to the recovery instance In the Lightsail dashboard, stop the original instance (the one you're locked out of). Go to Snapshots > Create Snapshot of the original instance’s disk (optional but good for safety). Go to the Networking tab, click Create a new disk from this instance (or go to Storage). Attach the disk to the recovery instance you created earlier.

Step 3: Mount the attached disk and fix UFW SSH into the recovery instance. run --> lsblk Identify the attached volume (e.g., /dev/xvdf1) Mount it: sudo mkdir /mnt/recovery sudo mount /dev/xvdf1 /mnt/recovery Disable UFW for the original system: sudo chroot /mnt/recovery ufw disable exit Unmount the disk: sudo umount /mnt/recovery

Step 4: Detach the disk and reattach to original instance Stop the recovery instance. Detach the volume from it. Reattach the volume back to the original instance (if it was a root disk) or simply restart the original instance if the disk was never detached. Start the original instance again.

Step 5: Try SSH again Use the web SSH console or your .pem key from a terminal.

answered a year ago

  • The steps mentioned above are inapplicable and invalid for Lightsail.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.