How to allow root SSH access for AWS EC2
For some cases you might need allow SSH root account connections like
[email protected]_address. In hint we will show how to do it for Amazon EC2 instances.
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:
22to allow SSH connection
- all ports that your application are listening on (e.g.
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:
Login by keypair
ubuntu user with
.pem file downloaded from AWS Console:
ssh -i ~/xx.pem [email protected]_ip
sudo nano /etc/ssh/sshd_config
Add lines to the end (These settings are required to properly work with docker builds):
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:
By doing this you allow direct connection using your ssh key with command from your OS user, like this: