Automate root SSH key login—securely, in one step.
- Configures SSH key-based login for the
rootuser on an Ubuntu Lightsail VPS. - Automatically updates
/etc/ssh/sshd_configto setPermitRootLogin yes. - Copies the
ubuntuuser’s SSH key to therootuser’s authorized keys. - Secures file permissions for the
rootuser’s SSH configuration. - Restarts the SSH service to apply changes.
No manual configuration. No incomplete setups.
-
SSH into your Lightsail Ubuntu server as the
ubuntuuser:ssh -i /path/to/key.pem ubuntu@your-server-ip
-
Run the one-liner script:
bash <(curl -s https://raw.githubusercontent.com/Monster-ZeroX/Enable-Root-SSH-Login-on-AWS/refs/heads/main/enable-root-ssh.sh) -
Log in as
rootwith your SSH key:ssh -i /path/to/key.pem root@your-server-ip
By default, AWS Lightsail and Ubuntu disable direct root SSH login for security reasons. However, enabling it is sometimes necessary for:
- Automation tasks.
- System recovery.
- Advanced server configurations.
This script ensures secure setup by using SSH keys only, avoiding less secure password-based authentication.
- Never enable password-based root login.
- Use strong, unique SSH keys.
- Disable root login when no longer needed (
PermitRootLogin no).
- Updates or inserts
PermitRootLogin yesin/etc/ssh/sshd_config. - Copies the
ubuntuuser’s SSH keys to/root/.ssh/authorized_keys. - Sets secure permissions for the
rootuser’s SSH configuration. - Restarts the SSH service to apply changes.
[*] Enabling root SSH login with SSH key...
[+] Root SSH key login is ENABLED. Try: ssh -i /path/to/key.pem root@<your-server-ip>