# why am i not able to access id\_rsa.pub as another user?

**URL:** <https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885>\
**Category:** Ansible Project\
**Created:** [July 22, 2022, 12:54pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885 "2022-07-22T12:54:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 22, 2022, 12:54pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885/1 "2022-07-22T12:54:59Z")

</div>

I still keep geting this error

fatal: [localhost]: FAILED! =\> {“msg”: “An unhandled exception occurred while templating ‘{{ lookup(‘file’, ‘/home/rke/.ssh/id\_rsa.pub’)}}’. Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: An unhandled exception occurred while running the lookup plugin ‘file’. Error was a \<class ‘ansible.errors.AnsibleError’\>, original message: could not locate file in lookup: /home/rke/.ssh/id\_rsa.pub”}

The file does exist but the user running the task dont have access. So I used become: root  
and become\_method: sudo

but still dont work

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 22, 2022, 2:20pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885/2 "2022-07-22T14:20:47Z")

</div>

simple permissions, can you 'cat '/home/rke/.ssh/id\_rsa.pub` ? you  
probably get same permissions error.

You either need to run ansible-playbook as a user with permissions  
(rke, root?) or use a task to read the file while using privilege  
escalation (become):

- slurp:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: , '/home/rke/.ssh/id\_rsa.pub'  
&nbsp;&nbsp;become: yes  
&nbsp;&nbsp;delegate\_to: localhost  
&nbsp;&nbsp;register: rke\_pub\_key

This is the equivalent of you doing `sudo cat  
/home/rke/.ssh/id\_rsa.pub' (lookups always run 'locally and are not  
affected by become, which only affects the 'remote' side of a task).

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 22, 2022, 4:44pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885/3 "2022-07-22T16:44:32Z")

</div>

thats what im trying to do

---

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 22, 2022, 5:27pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885/4 "2022-07-22T17:27:41Z")

</div>

so does it mean I am unable to use elevate privileges using lookup?

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [July 23, 2022, 7:02pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885/5 "2022-07-23T19:02:00Z")

</div>

> simple permissions, can you 'cat '/home/rke/.ssh/id\_rsa.pub` ? you  
> probably get same permissions error.

The $HOME/.ssh/ directory is normally restricted in its permissions to  
permit the SSH private keys there to be used. It's partly why Ansible  
has hooks to store private, and public, keys in the ansible vault  
rather than merely pulling them from the local filesystem. The public  
keys are not usually such an issue to publish as part of the playbook  
or the ansible configuration itself. Is there any compelling reason  
not to store such a reference public key in the playbook's  
configuration files?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 25, 2022, 1:04pm UTC](https://forum.ansible.com/t/why-am-i-not-able-to-access-id-rsa-pub-as-another-user/36885/6 "2022-07-25T13:04:35Z")

</div>

> so does it mean I am unable to use elevate privileges using lookup?

exactly
