For some cases you might need allow SSH root account connections like ssh root@ip_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:

  • 22 to allow SSH connection
  • all ports that your application are listening on (e.g. 80, 443) if you will host a website

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/id_rsa.pub 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_ rsa.pub your cat command will fail. Then run on your local machine:

ssh-keygen 

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

ssh root@<APP_HOST_IP>