How to allow root SSH access for AWS EC2

For some cases you might need allow SSH root account connections like ssh [email protected]_address. In hint we will show how to do it for Amazon EC2 instances.

We used Ubuntu 18.04 OS for Amazon EC2 t3a.small instance (you can use any hosting).

When you create an instance, you need to also open TCP ports:

Many VPS/Dedicated hosting providers have all ports open by default, when in Amazon EC2, all ports are closed by default, and you need open them in Security Group configuration. To do it on instance launch dialog:

Image for a hint

Login by keypair

Login as ubuntu user with .pem file downloaded from AWS Console:

ssh -i ~/xx.pem ubuntu@instance_ip

Edit file: sudo nano /etc/ssh/sshd_config

Add lines to the end (These settings are required to properly work with docker builds):

PermitRootLogin yes
MaxSessions 500
MaxStartups 500

Run service sshd restart to apply changesβœ….

Add your local public ssh key πŸ”‘ content (cat ~/.ssh/ on your local machine) to the next file on remote host (add to beginning with one line break after):

sudo vim /root/.ssh/authorized_keys

If you had no id_ your cat command will fail. Then run on your local machine:


By doing this you allow direct connection using your ssh key with command from your OS user, like this:

ssh [email protected]<APP_HOST_IP>

#ssh #ec2
Ivan Borshchov profile picture
Dec 25, 2020
by Ivan Borshchov
Did it help you?
Yes !

Best related