Enabling Root log in and SSH Log-in to use it as managed node for Ansible

Sayed Imran
4 min readDec 13, 2020

--

In this article you will be able to know how to enable root log in and SSH log in EC2-instance so that you can use it as a managed node for Ansible.

Usually when you try to log in into ec2 instance we log in with ec2-user then we switch to root by sudo su — root.

So to enable root log in go to /etc/ssh/sshd_config file

Command : vim /etc/ssh/sshd_config

In many cases the root log is permitted still I’ve shown this part

The position of mouse pointer should not be commented if it’s commented then uncomment it.

then save the file with Esc then :wq

Then go to the .ssh folder

Then omit the highlighted part in the authorized_keys file:

This is how it should be there

Now root log in is possible but for root log in also you need the key

here in my case I need to use the test_key.pem key to log in to the instance

So if you want to log from the red hat system you need to create the ssh key in the controller node and need to paste the details in the authorized_keys file of the instance.

You can create the password for the root

by passwd command in the root account:

Steps to create ssh key in controller node pasting the content in the right place to enable root log with password rather than key:

Go to the .ssh folder in the controller node:

Run the command ssh-keygen

don’t type anything just press enter whenever any thing asked

This is how you should proceed in SSH key creation

After successful creation of key you can see two files created:

id_rsa and id_rsa.pub

You just simple need to copy the content of the id_rsa.pub file into the authorized_keys of the instance.

Content of id_rsa.pub file

copy this content to the ec2-instace’s authorized_keys file:

  • Make sure you paste the content in new line and the save the file

Now restart the sshd service by systemctl restart sshd

Now with the controller node you can directly log in to the ec2 instance without any key or password also:

NOTE: You will be able to log into the ec2-intance only with the controller node without password or the instance key

See I tried to log from windows and I was denied access:

Now in the ansible hosts file you can paste the public IP of the Instance and ansible_ssh_user=root that’s it now you can use the instance as managed node.

Hope this article was useful to you.

Please DM me if you want any help regarding this and also let me know if I helped you.

My Linkedin profile:

https://www.linkedin.com/in/sayed-imran-b195741b4/

--

--

Sayed Imran
Sayed Imran

Written by Sayed Imran

Multi Cloud Certified | CKAD | AWS-SAA | GCP-PCA | AZ-104 | Cloud and DevOps Enthusiast |

No responses yet