- What to do when SSH access to the Lightsail server is lost?
- Common reasons for SSH loss
- Stage Zero — Quick Checks (Before Any Heavy Action)
- Recovery Methods — From Easy to Advanced
- 1) Using a Web Console Connection (Browser-based SSH) or Serial Console
- 2) Check the Lightsail firewall
- 3) If private key is lost — download default regional key
- 4) Check disk space and restart services (if you have access to the console)
- 5) Basic Rescue Method: snapshot → create auxiliary disk/instance → mount → chroot → modify settings
- 6) Complete replacement with instance from snapshot (less hassle and fast)
- 7) Password reset for Windows
- Checklist and useful commands for troubleshooting after recovery
- Security tips and best practices to prevent being locked out again
- Practical example — Scenario: authorized_keys is cleared
- When all else fails — Contact Support and Data Recovery
- Conclusion and final recommendation
- Frequently Asked Questions
What to do when SSH access to the Lightsail server is lost?
In production environments, losing SSH access to an Amazon Lightsail server can cause service outages and damage. Here's a step-by-step, technical and practical guide to recovering from a server that doesn't have SSH access: from quick checks to a rescue method with snapshots and disk attachment to a backup instance.
Common reasons for SSH loss
Some common reasons that cause SSH access to be interrupted:
- Change or deterioration
/etc/ssh/sshd_config - File permissions error
~/.sshOr/root/.ssh(permissions) - File deletion or corruption
authorized_keys - Disk full which prevents sshd from starting or writing logs
- Internal firewall changes (
ufw/iptables) or Lightsail Firewall (Networking → Firewall) - Package deletion or corruption
openssh-server - SELinux or AppArmor issues
- Lost local private key or incorrect key pair
- A system that boots incorrectly or has a filesystem error
Stage Zero — Quick Checks (Before Any Heavy Action)
Before starting more complex methods, check these to reach a solution faster.
- Check the instance status (running / stopped) in the Lightsail panel.
- In the section Networking Make sure the SSH rule (TCP 22) is enabled.
- Button Connect using SSH (browser-based) Try Lightsail in the panel.
- If there are any possible firewall changes on the server, check the logs from the console or CloudWatch logs.
- If you have access to the serial console, check the ssh logs:
journalctl -u sshd -bOrtail -n 200 /var/log/auth.log
Recovery Methods — From Easy to Advanced
In this section, the methods are explained in order from least troublesome to most complete.
1) Using a Web Console Connection (Browser-based SSH) or Serial Console
The web console can sometimes connect even when the connection with the local private key is not working. If the web console does not connect, continue to the next steps.
2) Check the Lightsail firewall
In the Lightsail → Networking → Firewall panel, check that a rule exists for port 22:
- Protocol: TCP
- Port range: 22
If it was closed, open it and try again.
3) If private key is lost — download default regional key
Lightsail manages SSH keys by region. Account → SSH keys Go and download the key for your region. Then try it out:
ssh -i ~/.ssh/lightsail_default_key.pem ubuntu@<public-ip>4) Check disk space and restart services (if you have access to the console)
If the web console opens, first check the disk space and perform a cleanup operation if it is full.
df -h
sudo journalctl --vacuum-time=2d
sudo apt-get autoremove -y
sudo journalctl -u ssh -b --no-pager
sudo tail -n 200 /var/log/auth.log5) Basic Rescue Method: snapshot → create auxiliary disk/instance → mount → chroot → modify settings
This method is used when the console is not connected or system files need to be modified.
General steps:
- From the desired instance, a Snapshot Take (Lightsail → Create snapshot).
- Create a new block storage disk or instance from this snapshot.
- Create a rescue instance with the same distribution.
- Connect the created disk to the Rescue instance.
- Log in to the Rescue instance and find the disk with
lsblkAnd then mount.
Example commands for mount and chroot (assuming the disk is /dev/xvdf1 Connected):
sudo lsblk
sudo mkdir -p /mnt/rescue
sudo mount /dev/xvdf1 /mnt/rescue
sudo mount --bind /dev /mnt/rescue/dev
sudo mount --bind /proc /mnt/rescue/proc
sudo mount --bind /sys /mnt/rescue/sys
sudo chroot /mnt/rescue /bin/bashIn the chroot environment, important actions include:
- Return
authorized_keysSuitable for the user - Installation or renovation
openssh-server - Review and correction
/etc/ssh/sshd_config - Enabling the ssh service
Example commands inside chroot:
mkdir -p /home/ubuntu/.ssh
echo "ssh-rsa AAAA... your-public-key ..." >> /home/ubuntu/.ssh/authorized_keys
chown -R ubuntu:ubuntu /home/ubuntu/.ssh
chmod 700 /home/ubuntu/.ssh
chmod 600 /home/ubuntu/.ssh/authorized_keys
apt-get update && apt-get install --reinstall openssh-server -y
# Ensure sshd config allows key auth and, if needed temporarily, password auth
# Example: PubkeyAuthentication yes, PermitRootLogin prohibit-password, PasswordAuthentication yes
systemctl enable ssh
systemctl restart sshExit chroot and unmount the disk:
exit
sudo umount /mnt/rescue/sys
sudo umount /mnt/rescue/proc
sudo umount /mnt/rescue/dev
sudo umount /mnt/rescueFinally, detach the disk and either reconnect it to the original instance or create a new instance from it and transfer the static IP to Lightsail.
vgchange -ay Or there may be a code unlocking.6) Complete replacement with instance from snapshot (less hassle and fast)
If you don't want to mess with mount/chroot:
- Create a new instance from the snapshot.
- Connect to the new instance with the default key or web console.
- If necessary, detach the previous static IP from the old instance and attach it to the new instance.
This method is quick but may require network or device-specific settings.
7) Password reset for Windows
For Linux that PasswordAuthentication It is enabled, you can chroot with password username Change the password.
For Windows Lightsail, it is usually possible to extract the RDP password from the Lightsail panel or use a snapshot to create a new instance.
Checklist and useful commands for troubleshooting after recovery
- Check ssh permissions and files:
sudo ls -la /home/ubuntu/.ssh sudo stat -c "%a %n" /home/ubuntu/.ssh /home/ubuntu/.ssh/authorized_keys - Check the ssh service:
sudo systemctl status ssh sudo journalctl -u ssh -n 200 - Firewall check:
sudo ufw status verbose sudo iptables -L -n -v - Check disk space and logs:
df -h du -sh /var/log/* sudo tail -n 200 /var/log/auth.log sudo tail -n 200 /var/log/syslog
Security tips and best practices to prevent being locked out again
- Always have at least one extra SSH key In
authorized_keysHold (collaborator or backup key). - From configuration management Use tools like Ansible/Chef/Puppet to make sensitive changes so that changes are reversible.
- Use periodic and automated snapshots.
- To prevent attacks, use a network firewall and tools like fail2ban, and restrict SSH access with IP whitelisting.
- Enable centralized logging (e.g. sending logs to S3 or an external log server) so that logs are accessible in case of problems.
- Avoid logging in directly as root; use a user with
sudoUse.
PasswordAuthentication yes Severe, disable it immediately after resolving the problem to reduce the security risk.Problem: Local key not working and authorized_keys Deleted.
Quick solution: snapshot → disk → attach to rescue instance → mount → restore authorized_keys → reattach or create a new instance → attach static IP.
sudo lsblk
sudo mount /dev/xvdf1 /mnt/rescue
sudo mkdir -p /mnt/rescue/home/ubuntu/.ssh
sudo echo "ssh-rsa AAAA... your-public-key" >> /mnt/rescue/home/ubuntu/.ssh/authorized_keys
sudo chown -R 1000:1000 /mnt/rescue/home/ubuntu/.ssh
sudo chmod 700 /mnt/rescue/home/ubuntu/.ssh
sudo chmod 600 /mnt/rescue/home/ubuntu/.ssh/authorized_keysWhen all else fails — Contact Support and Data Recovery
If manual configuration is not possible or data integrity is at risk:
- Use previous snapshots or contact Lightsail/AWS support.
- If the service is critical and you need to migrate immediately, create a new instance and update the DNS or static IP to keep the service running.
Conclusion and final recommendation
Recovering a Lightsail server without SSH access is usually done in one of two ways:
- Quick fix Via console / key recovery / firewall unlocking — low cost and fast
- Rescue method With snapshot and disk attachment to a helper instance for mount and chroot — more robust and fully recoverable files
By taking regular snapshots and following security tips, you can significantly reduce the risk of SSH access being locked out.








