# Problem with SSH keys

**URL:** <https://forum.ansible.com/t/problem-with-ssh-keys/15303>\
**Category:** Ansible Project\
**Created:** [May 22, 2014, 12:42pm UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303 "2014-05-22T12:42:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruggero\_Marchei](https://avatars.discourse-cdn.com/v4/letter/r/dfb087/32.png) [@Ruggero\_Marchei](https://forum.ansible.com/u/Ruggero_Marchei)\
**Post date:** [May 22, 2014, 12:42pm UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303/1 "2014-05-22T12:42:37Z")

</div>

I’m using the authorized\_key module to distribute ssh keys to my server, loading a key this way:

> >

`  
authorized\_key: user=root key=“{{ item }}”  
with\_file:

- my\_key.pub

`

the source key file contains an entry like:

`  
from=“hostname.domain,10.0.0.\*” ssh-rsa AAAAB3NzaCBLAHBLAHBLAH…

`

but when it’s written in the authorized\_keys of the target host it appears in the form:

`from=hostname.domain,10.0.0.* ssh-rsa AAAAB3NzaCBLAHBLAHBLAH...`

The key written in the target misses the quotation marks and doesn’t work as expected.

The problem seems to be located when \_load\_params calls the shlex.split() function and removes the quotation marks:

`  
MODULE\_ARGS = ‘user=root key="from=“hostname.domain,10.0.0.\*” ssh-rsa AAAAB3NzaCBLAHBLAHBLAH… "’

…

def \_load\_params(self):  
‘’’ read the input and return a dictionary and the arguments string ‘’’  
args = MODULE\_ARGS  
**items** **= shlex.split(args)**  
`

items now contains something like:

`['user=root', 'key=from=hostname.domain,10.0.0.* ssh-rsa AAAAB3NzaCBLAHBLAHBLAH...`

I don’t know if I am doing something wrong or if it is some kind of bug

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [May 22, 2014, 3:42pm UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303/2 "2014-05-22T15:42:28Z")

</div>

This is the same problem described here:

&nbsp;&nbsp;&nbsp;&nbsp;[https://github.com/ansible/ansible/issues/6294](https://github.com/ansible/ansible/issues/6294)

I can confirm that the workaround mentioned on that page (of passing the  
values as a hash instead of key=value) works for me. Unfortunately, per  
the explanation on that page, this is not something that will be fixed.

-- ams

---

<div class="post-metadata">

**Author:** ![Ruggero\_Marchei](https://avatars.discourse-cdn.com/v4/letter/r/dfb087/32.png) [@Ruggero\_Marchei](https://forum.ansible.com/u/Ruggero_Marchei)\
**Post date:** [May 23, 2014, 11:51am UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303/3 "2014-05-23T11:51:43Z")

</div>

Thanks ams,

I’ve tried the workaround suggested by Michael, passing the arguments as hash members, and it works perfectly!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 23, 2014, 12:40pm UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303/4 "2014-05-23T12:40:35Z")

</div>

I’m not sure I agree with Abhijit as it seems this could be solved by the authorized\_key module knowing when to quote and calling pipes.quote.

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [May 23, 2014, 3:30pm UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303/5 "2014-05-23T15:30:48Z")

</div>

Hi Michael. If the disagreement is about the "not something that will be  
fixed part", I was just quoting what you said in the ticket I linked to  
([https://github.com/ansible/ansible/issues/6294](https://github.com/ansible/ansible/issues/6294)):

&nbsp;&nbsp;&nbsp;&nbsp;"This isn't going to be fixable but is a consequence of how the  
&nbsp;&nbsp;&nbsp;&nbsp;lookup plugin is evaluating your line."

If you think it can be fixed, I'm delighted to hear it. If you explain  
in a bit more detail what you have in mind, I'll even volunteer to  
produce a pull request along those lines.

-- ams

---

<div class="post-metadata">

**Author:** ![Ruggero\_Marchei](https://avatars.discourse-cdn.com/v4/letter/r/dfb087/32.png) [@Ruggero\_Marchei](https://forum.ansible.com/u/Ruggero_Marchei)\
**Post date:** [May 23, 2014, 10:38pm UTC](https://forum.ansible.com/t/problem-with-ssh-keys/15303/6 "2014-05-23T22:38:42Z")

</div>

I think quoting in the authorized\_key module would be a problem in a case like:

from=“192.168.0.1”,no-user-rc # no-user-rc is an option  
from=“192.168.0.1,no-user-rc” # no-user-rc is a host

both are passed to the module as:

from=192.168.0.1,no-user-rc

(It is very unlikely to happen, but you know…)

What about a specific “sshkey” lookup plugin?
