July 13, 2021 . 2 MIN READ
Wow to Enable SSH as root on AWS Ubuntu Instance
Generally when you tried to access Ubuntu vm on AWS server as user ‘root‘. You will find a message like below. It means you can’t SSH to your server directly using root account, and first you have to login as user ‘ubuntu’ first and then use ‘sudo su –‘ to get root access.
Please login as the user “ubuntu” rather than the user “root”.
Warning => One of bigger security hole you are going to create in your server by opening direct root access. We recommend to not to do this until a more specific reason.
Follow the below steps to enable ssh as root user on AWS ubuntu instances. The same steps you can follow for other Linux distributions AWS instances like CentOS, RHEL, LinuxMint, Debian etc.
· $ ssh -i server.pem ubuntu@remote-server.com
After successful login to ubuntu account switch to root account.
$ sudo su –
· 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″ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCPqJ2U4gidqek· 4FPQJABENkrUiLVP61LObdFAZXvs2EpCf/nBQCRg4ykMNg+8TC9lb7jC65zfIrTUcNcwongDb4· 3k6miSKu1M8fdqXDpcb8CdDRaKpM2wP8l+hTaJ2aWycXmGJ7lZKQPiwNUOhbrOLNEtDmOI9eiV· lz7See98LVLW+6AwfzNA8Cu4riDTvEMQr/WQ9NLrS3BZE1TAAswJi9lGDfTgEvfh4Ji+eI/xT· Xrjkkwjerkjk3jrkwejrkjwe9wASXob4rbV12TXjQIcMKaRGQAGrwOHu0nM2ibfTdgqjrTAG· 03CXKzQhF09LdxKlT7GpYe0oVU2R1kjkejwQp tecadmin.net
Remove the highlighted text from authorized_keys file and your key should be look like this. There are no space before ssh-rsa text.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCPqJ2U4gidqek4FPQJABENkrUiLVP61LObdFAZXvs2EpCf/nBQCRg4ykMNg+8TC9lb7jC65zfIrTUcNcwongDb43k6miSKu1M8fdqXDpcb8CdDRaKpM2wP8l+hTaJ2aWycXmGJ7lZKQPiwNUOhbrOLNEtDmOI9eiVlz7See98LVLW+6AwfzNA8Cu4riDTvEMQrWQ9NLrS3BZE1TAAswJi9lGDfTgEvfh4Ji+eIxTXrjkkwjerkjk3jrkwejrkjwe9wASXob4rbV12TXjQIcMKaRGQAGrwOHu0nM2ibfTdgqjrTAG03CXKzQhF09LdxKlT7GpYe0oVU2R1kjkejwQp tecadmin.net
· $ ssh -i server.pem root@remote-server.com
You will find that you have successfully logged in to server with root user directly.