DEV Community

Abhishek Korde
Abhishek Korde

Posted on

1 1 1 1 1

How to configure passwordless authentication using Ansible

There are many method in ansible for configuring password-less Authentication like:

  1. copy public key to remote hosts
  2. Test SSH Access
  3. Configure Ansible Invertory
  4. Run Ansible ping Test
  5. Generate SSH Key Generally I prefers Generate SSH key because secure, efficient, and automated way to manage infrastructure. first thing is to install ansible in your system using below commands:

Image description

Image description
create I create two EC2 instances in AWS Servers.

Image description
main server we are using is Ansible_server and target_server is target_ubuntu
login in Ansible_server first and trying to talk to with target_server i.e target_ubuntu
for login Ansible_server, write following command:

Image description
This ssh-keygen will generate key for you like below it will ask for information
Image description
after that there is one directory is created and in that directory there is set of files.
these files stored in /home/ubuntu/.ssh/
id_rsa will store private key and id_rsa.pub will store public key
go to that directory where are key are stored.

Image description
this will print the public key, copy this public key and login in target_server and do same process.
Image description

Image description
This will create same set of files.then open the authorized_keys file and paste the copied the public ip address.
after completing this come back to main server i.e Ansible_servers and write below command:

Image description
command: ssh ip_address, this ip address is private ip address of terget server.
now see we are sucessfully login our targer_server without any password
Github:https://github.com/abhikorde31/ansible-examples
summary:by using ssh-keygen, we copy the public ip address of main_server i.e Ansible_server and paste in authorized_key of target_server.

Top comments (0)

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay