How to enable root ssh in Amazon Lightsail instance

Amazon lightsail instances do not allow ssh root access by default. You have to log in as user “ubuntu” or “ec2-user”, then use the command “sudo” to become user root. This is done for security. There are some circumstances where you need to enable direct SSH login to lightsail server.

How to enable root ssh in ubuntu lightsail instgance

Login as user ubuntu, then edit the file

sudo vi /root/.ssh/authorized_keys 

In the file, you will notice the default ssh key has already been added. But in the front the line, you have the following string

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10" 

You need to remove this text, so you have the ssh key remaining in the file. SSH public key starts with the text ssh-rsa.

Now you should be able to log in to the server with SSH user root and default ssh key file (pem file).

Back to Amazon Lightsail

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *