Implementing Passwordless Authentication with Ansible

Harsh SoniHarsh Soni
3 min read

In this blog, I explore three common methods of setting up passwordless authentication: using SSH keys, SSH-copy-id, and password-less configurations. Passwordless authentication is a secure, efficient way to access remote systems without entering passwords each time, enhancing both convenience and security. I’ll walk through each method, breaking down the setup process for seamless, password-free logins.

I have created 3 EC2 instances on AWS and I will use my local machine as a control node to perform password-less authentication on all the instances

Using SSH Keys

Lets try to perform passwordless authentication on ‘manage-node-1’ using ssh-keys.

I have created private and public keys using this below command

ssh-keygen

it will create .ssh folder and that folder contains private and public key

Connect to manage-node-1 from the AWS console. Copy the control node's public key and paste it into the authorized_keys file on manage-node-1.

Try to log in to manage-node-1 without using a password or any keys.

ssh ubuntu@<public ip address>

Login Successful 🎉

Using SSH-copy-id

Copy the key pair to a safe directory. We will use this key pair to perform passwordless authentication on manage-node-2.

Note: This keypair.pem should be the same one used during the creation of manage-node-2.

ssh-copy-id -f "-o Identityfile <path_of_keypair.pem>" [user@]hostname

Try to log in to manage-node-2 without using a password or any keys.

Login Successful 🎉

Using Password Configuration

Connect to manage-node-3 using AWS Console. Edit this file ‘60-cloudimg-settings.conf” and update ‘PasswordAuthentication yes’

Restart ssh process

sude systemctl restart ssh

Create a password for current user

sudo passwd ubuntu
New Pass:
Retype Pass:

Now, try to connect manage-node-3 from control-node ( laptop ) using ssh-copy-id <username@public ip>

You need to enter the password the first time you connect to manage-node-3. After that, when you try to connect again, it won't ask for a password.

Login Successful 🎉

Conclusion

Setting up passwordless authentication between control and managed nodes enhances both security and efficiency. This method simplifies node management, allowing you to automate tasks securely and focus on more complex DevOps operations.


Join the community of learners and be a part of the conversation! Your feedback is valuable to us, so please share your thoughts in the comments section. Help us make this blog even better for everyone. And if you found this post helpful, spread the word! Share it with those who could benefit from the information. And don't forget to follow along and subscribe to our newsletter for instant updates on our latest content. Thank you for taking the time to read and engage with us!

1
Subscribe to my newsletter

Read articles from Harsh Soni directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harsh Soni
Harsh Soni

👋 Hello! I'm Harsh, a DevOps enthusiast driven by a passion for continuous learning and innovation. With hands-on experience across cloud platforms, infrastructure tools, and programming languages, I'm committed to creating scalable, automated, and efficient solutions. Let’s connect, share knowledge, and build amazing things together! SKILLS: 🔹Languages & Runtimes: Python, C#, Shell Scripting, YAML 🔹Cloud Expertise: AWS (proficient in EC2, ELB, EBS, S3, VPC, Route53, SES, SNS, CloudFormation, CloudWatch) 🔹Infrastructure & DevOps Tools: Docker, Terraform, AWS CloudFormation 🔹Development & CI/CD: Linux, Git, GitHub Actions, Jenkins, Jira, GitLab (beginner), AWS DevOps 🔹Web Development: HTML, CSS, Bootstrap, .NET, Python, SQL Why Connect with Me? I'm a detail-oriented professional with strong communication skills, always ready to tackle complex problems with a positive mindset. Whether you’re here to network or explore potential collaborations, feel free to reach out. Let’s grow together in the DevOps journey! 📧 Contact Me: harshsoni6011@gmail.com