ansible connection using rsa key

Hi All,

I want to know is there any way to get connect to the remote host with ansible control server using rsa key.

Instead of using user name and password I want to use rsa key for authentication.

How can we do that?

Looking forward for reply.

Thanks & Regards
Sumit Sahay

Likes this?

ansible-playbook -i hosts playbook.yml --key-file "~/.ssh/mykey.pem"

See in
https://stackoverflow.com/questions/44734179/specifying-ssh-key-in-ansible-playbook-file

Hi Cava,

Thanks for your reply.

While doing this, we don’t need to enter user credential in host file?
Is it so?

Looking for your reply.

Regards
Sumit Sahay

hi only the first time you have to copy the public key and insert the pwd

for example with
cat ~/.ssh/id_rsa.pub | ssh user@hostname ‘cat >> .ssh/authorized_keys’

or

ssh-copy-id -i ~/.ssh/mykey user@host

after when the key i present over the host
you can cannect without any password