# user\_module and ssh key

**URL:** <https://forum.ansible.com/t/user-module-and-ssh-key/29951>\
**Category:** Ansible Project\
**Created:** [March 22, 2019, 6:51am UTC](https://forum.ansible.com/t/user-module-and-ssh-key/29951 "2019-03-22T06:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_B](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Alexander\_B](https://forum.ansible.com/u/Alexander_B)\
**Post date:** [March 22, 2019, 6:51am UTC](https://forum.ansible.com/t/user-module-and-ssh-key/29951/1 "2019-03-22T06:51:13Z")

</div>

Hello.  
There are two hosts. On first I create a user and generate SSH keys. Now I need to transfer private key to second host to connect using it to first host without creating a user on second. I haven’t found an output of parameter ssh\_key as analogg to ssh\_public\_key in module user. In other modules related to SSH there is only a possibility to see contents of public key. What is the reason for this restriction?

The [documentation](https://docs.ansible.com/ansible/latest/modules/user_module.html) is written about the path to the ssh public key. in the example of a private key.

ssh\_key\_file Path to generated SSH public key file. **Sample** : /home/asmith/.ssh/id\_rsa

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [March 22, 2019, 7:14am UTC](https://forum.ansible.com/t/user-module-and-ssh-key/29951/2 "2019-03-22T07:14:09Z")

</div>

On 22.03.19 07:51, Alexander B. wrote:\> Hello.

> There are two hosts. On first I create a user and generate SSH keys.

Now I

> need to transfer private key to second host to connect using it to first  
> host without creating a user on second. I haven't found an output of  
> parameter ssh\_key as analogg to ssh\_public\_key in module user. In other  
> modules related to SSH there is only a possibility to see contents of  
> public key. What is the reason for this restriction?

Because the private key should be \_private\_ and not be transferred  
around the network.

If you need to be able to login from host2 to host1, you need to  
generate a ssh keypair on host2, (either using the user module or  
command module), fetch the contents of the public key, and use the  
authorized\_key module to put the public key into the authorized\_keys  
file for the user.

> The documentation  
> \<[https://docs.ansible.com/ansible/latest/modules/user\_module.html&gt](https://docs.ansible.com/ansible/latest/modules/user_module.html&gt); is  
> written about the path to the ssh public key. in the example of a private  
> key.
> 
> ssh\_key\_file Path to generated SSH public key file. \*Sample\*:  
> /home/asmith/.ssh/id\_rsa

That one is a bug in the docs, it's fixed in the devel docs:

[https://docs.ansible.com/ansible/devel/modules/user\_module.html](https://docs.ansible.com/ansible/devel/modules/user_module.html)

- Sebastian
