# ansible connection using rsa key

**URL:** <https://forum.ansible.com/t/ansible-connection-using-rsa-key/28572>\
**Category:** Ansible Project\
**Created:** [September 14, 2018, 6:52am UTC](https://forum.ansible.com/t/ansible-connection-using-rsa-key/28572 "2018-09-14T06:52:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SUMIT\_SAHAY](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SUMIT\_SAHAY](https://forum.ansible.com/u/SUMIT_SAHAY)\
**Post date:** [September 14, 2018, 6:52am UTC](https://forum.ansible.com/t/ansible-connection-using-rsa-key/28572/1 "2018-09-14T06:52:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cava\_cavamagie](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@cava\_cavamagie](https://forum.ansible.com/u/cava_cavamagie)\
**Post date:** [September 14, 2018, 6:57am UTC](https://forum.ansible.com/t/ansible-connection-using-rsa-key/28572/2 "2018-09-14T06:57:59Z")

</div>

Likes this?

```auto
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](https://stackoverflow.com/questions/44734179/specifying-ssh-key-in-ansible-playbook-file)

---

<div class="post-metadata">

**Author:** ![SUMIT\_SAHAY](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SUMIT\_SAHAY](https://forum.ansible.com/u/SUMIT_SAHAY)\
**Post date:** [September 14, 2018, 7:05am UTC](https://forum.ansible.com/t/ansible-connection-using-rsa-key/28572/3 "2018-09-14T07:05:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cava\_cavamagie](https://avatars.discourse-cdn.com/v4/letter/c/e68b1a/32.png) [@cava\_cavamagie](https://forum.ansible.com/u/cava_cavamagie)\
**Post date:** [September 14, 2018, 7:37am UTC](https://forum.ansible.com/t/ansible-connection-using-rsa-key/28572/4 "2018-09-14T07:37:43Z")

</div>

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
