# ssh root access remain closed

**URL:** <https://forum.ansible.com/t/ssh-root-access-remain-closed/34796>\
**Category:** Ansible Project\
**Created:** [March 16, 2021, 7:54pm UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796 "2021-03-16T19:54:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![reredok](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@reredok](https://forum.ansible.com/u/reredok)\
**Post date:** [March 16, 2021, 7:54pm UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/1 "2021-03-16T19:54:32Z")

</div>

Hello all,

one thing is not clear to me about ansible. On all my Linux VM the root ssh access, for security reasons, is blocked. So the ad-hoc, playbook access only works via a non-administrative user. But then, for example, to install something on the Linux VM, how do you change the user to root? I don’t want to work with ssh and public keys in my small environment and the root ssh access should remain closed.  
Thanks for any feedback

reredok

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [March 16, 2021, 8:12pm UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/2 "2021-03-16T20:12:57Z")

</div>

Use “become”.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 16, 2021, 8:22pm UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/3 "2021-03-16T20:22:11Z")

</div>

Explained in detail here  
[https://docs.ansible.com/ansible/latest/user\_guide/become.html](https://docs.ansible.com/ansible/latest/user_guide/become.html)

---

<div class="post-metadata">

**Author:** ![reredok](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@reredok](https://forum.ansible.com/u/reredok)\
**Post date:** [March 17, 2021, 7:37am UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/4 "2021-03-17T07:37:41Z")

</div>

Hello,  
i tried everything possible with “become” in the playbook:

Either the password is wrong or a password is needed.

To rule out that I have a problem with root, I temporarily set PermitRootLogin Yes in /etc/ssh/sshd\_config and then it works.

I have looked at the ansible documentation which I may not understand in full. Again for understanding:

There is an “ansible\_user” who connects remotely via ssh and I give him the password in the “Inventory” with ansible\_ssh\_pass. In the “playbook” I set “become: yes”," become\_user: root", “become\_method: sudo”. This then changes the ssh user to root and runs my “apt:” command.

Do you have an example that works for you? Thanks a lot

---

<div class="post-metadata">

**Author:** ![zoobarb](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@zoobarb](https://forum.ansible.com/u/zoobarb)\
**Post date:** [March 17, 2021, 8:05am UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/5 "2021-03-17T08:05:25Z")

</div>

This is more of a Unix question than an ansible question.

Your login ID should not be root.  
Your sudo file ,on destination host, should have your login ID defined with appropriate permissions.  
Use ssh keys for your login ID

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [March 17, 2021, 12:17pm UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/6 "2021-03-17T12:17:34Z")

</div>

The thing that works for me is:

$ ansible all -m command -a ’sudo uptime’ -o

I get no errors and I get a response from all my servers.

---

<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:** [March 17, 2021, 2:12pm UTC](https://forum.ansible.com/t/ssh-root-access-remain-closed/34796/7 "2021-03-17T14:12:18Z")

</div>

To verify permissions for the login user use `sudo -l `

this does NOT require root logins.
