Вы находитесь на странице: 1из 2

How 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.

Enable SSH as root on AWS Ubuntu:


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 to Server – Login to your server with ubuntu user and then switch to root user with
sudo command.

 $ ssh -i server.pem ubuntu@remote-server.com

After successful login to ubuntu account switch to root account.

$ sudo su -

 Edit authorized_keys File – Now edit /root/.ssh/authorized_keys file the private key of
yours. You will get something like code with your key.
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
AAAAB3NzaC1yc2EAAAADAQABAAABAQCPqJ2U4gidqek4FPQJABENkrUiLVP
61LObdFAZXvs2EpCf/nBQCRg4ykMNg+8TC9lb7jC65zfIrTUcNcwongDb43k6miSK
u1M8fdqXDpcb8CdDRaKpM2wP8l+hTaJ2aWycXmGJ7lZKQPiwNUOhbrOLNEtDm
OI9eiVlz7See98LVLW+6AwfzNA8Cu4riDTvEMQr/WQ9NLrS3BZE1TAAswJi9lGDf
TgEvfh4Ji+eI/xTXrjkkwjerkjk3jrkwejrkjwe9wASXob4rbV12TXjQIcMKaRGQAGrwO
Hu0nM2ibfTdgqjrTAG03CXKzQhF09LdxKlT7GpYe0oVU2R1kjkejwQp 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
AAAAB3NzaC1yc2EAAAADAQABAAABAQCPqJ2U4gidqek4FPQJABENkrUiLVP
61LObdFAZXvs2EpCf/nBQCRg4ykMNg+8TC9lb7jC65zfIrTUcNcwongDb43k6miSK
u1M8fdqXDpcb8CdDRaKpM2wP8l+hTaJ2aWycXmGJ7lZKQPiwNUOhbrOLNEtDm
OI9eiVlz7See98LVLW+6AwfzNA8Cu4riDTvEMQr/WQ9NLrS3BZE1TAAswJi9lGDf
TgEvfh4Ji+eI/xTXrjkkwjerkjk3jrkwejrkjwe9wASXob4rbV12TXjQIcMKaRGQAGrwO
Hu0nM2ibfTdgqjrTAG03CXKzQhF09LdxKlT7GpYe0oVU2R1kjkejwQp tecadmin.net

 Save File – After removing above highlighted text from authorized_keys file, save it and
try to ssh with root account.

 $ ssh -i server.pem root@remote-server.com

You will find that you have successfully logged in to server with root user directly.

https://tecadmin.net/how-to-enable-ssh-as-root-on-aws-ubuntu-instance/

Вам также может понравиться