# Using sudosh instead of just sudo

**URL:** <https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107>\
**Category:** Ansible Project\
**Created:** [September 3, 2014, 4:32pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107 "2014-09-03T16:32:21Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren\_Johnson](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Darren\_Johnson](https://forum.ansible.com/u/Darren_Johnson)\
**Post date:** [September 3, 2014, 4:32pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/1 "2014-09-03T16:32:21Z")

</div>

I am trying to meet a corporate requirement wherein ansible’s actions are recorded by sudosh on each server it touches. I tried changing “executable” from /bin/sh to /usr/bin/sudosh, but sudosh doesn’t have the corresponding -c parameter (it has one, but with different meaning). I tried making ansible’s login shell be /usr/bin/sudosh. That works for non-sudo operations–I can _ls /tmp_ and that works. However, if I try to sudo from the sudosh shell, I get the following error:

…isn’t allowed to be executed with process or redirect controls.

I don’t see a lot of information on this particular error in the context of sudo/sh.

Is it even feasible/possible to do what I’m trying to do?

Thanks…

Darren

---

<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:** [September 3, 2014, 7:15pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/2 "2014-09-03T19:15:03Z")

</div>

Hi Darren,

Hmm… so yeah if [http://docs.ansible.com/intro\_configuration.html#sudo-exe](http://docs.ansible.com/intro_configuration.html#sudo-exe) does not help, it seems we need to have another setting that if set adds the “-c”, so it can be removed.

Maybe this would work if it were tunable?

I believe this would be easy to implement.

Something like “base\_sudo\_flags=-c” # etc

and you could remove it…

–Michael

---

<div class="post-metadata">

**Author:** ![Darren\_Johnson](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Darren\_Johnson](https://forum.ansible.com/u/Darren_Johnson)\
**Post date:** [September 9, 2014, 9:39pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/3 "2014-09-09T21:39:04Z")

</div>

So I separated out the sudosh from the sudo. Having sudosh as a login shell works and records like it should, so I don’t think you need to have another setting.

This works:  
ansible myserver -a “ls /tmp” and so does this: ansible myserver -a “sudo ls /tmp”

This doesn’t:  
ansible myserver -a “ls /tmp” --sudo

That is where I get the redirection error.

Darren

---

<div class="post-metadata">

**Author:** ![Craig\_Wickesser](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Craig\_Wickesser](https://forum.ansible.com/u/Craig_Wickesser)\
**Post date:** [November 5, 2014, 10:20am UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/4 "2014-11-05T10:20:36Z")

</div>

I have a similar requirement. Most operations are locked down to root, so I can SSH to a host as myself and then “sudo sudosh” to become root and do what I need. Is it possible to do this with Ansible?

For example, as myself I can’t check the status of docker (running “service docker status” returns "docker status unknown due to insufficient privileges).

I’ve tried using combinations of “remote\_user”, “sudo” and “sudo\_user” without luck, ansible hangs b/c it’s trying to do “sudo …” which I can’t do (I have to “sudo sudosh”, then I can run things). I could possibly have changes made to /etc/sudoers to allow my user to be able to “sudo” certain commands, but what I’m not sure which commands I’d need to enable.

Thanks in advance for any help.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Nezis](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Nicholas\_Nezis](https://forum.ansible.com/u/Nicholas_Nezis)\
**Post date:** [March 15, 2017, 8:27pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/5 "2017-03-15T20:27:27Z")

</div>

Was there ever a resolution to this? I’m running into the same issue. “sudo sudosh” is my only option for privilege escalation.

Thanks,  
Nick

---

<div class="post-metadata">

**Author:** ![Nicholas\_Nezis](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Nicholas\_Nezis](https://forum.ansible.com/u/Nicholas_Nezis)\
**Post date:** [March 16, 2017, 1:45am UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/6 "2017-03-16T01:45:17Z")

</div>

Was there ever a resolution to this? I’m in a similar situation in which I can only switch to root using “sudo sudosh” or “sudo -s”. I’ve tried using “become\_flags: ‘-s’”, but with no luck. Am I missing something else?

---

<div class="post-metadata">

**Author:** ![Craig\_Wickesser](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Craig\_Wickesser](https://forum.ansible.com/u/Craig_Wickesser)\
**Post date:** [March 16, 2017, 10:36am UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/7 "2017-03-16T10:36:49Z")

</div>

Nick - the only thing that ended up working for us was to add the commands we needed to run to /etc/sudoers ( in believe that’s the correct place). That was very painful and annoying.

We ended up switching to Salt.

Good luck!

---

<div class="post-metadata">

**Author:** ![Nicholas\_Nezis](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Nicholas\_Nezis](https://forum.ansible.com/u/Nicholas_Nezis)\
**Post date:** [March 17, 2017, 1:48am UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/8 "2017-03-17T01:48:17Z")

</div>

Looks like this might solve my issue. [https://github.com/ansible/ansible/issues/22718#issuecomment-287193691](https://github.com/ansible/ansible/issues/22718#issuecomment-287193691)

Set “executable” in the ansible.cfg to “sudosh”

I’ll have to try it tomorrow at work.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Nezis](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Nicholas\_Nezis](https://forum.ansible.com/u/Nicholas_Nezis)\
**Post date:** [March 21, 2017, 11:50am UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/9 "2017-03-21T11:50:29Z")

</div>

I wasn't successful. Not sure if you can run commands in conjunction with the privilege escalation. With "sudo sudosh" you have to completely switch to root, and then rub your commands.

---

<div class="post-metadata">

**Author:** ![clifford.trueman](https://avatars.discourse-cdn.com/v4/letter/c/b9bd4f/32.png) [@clifford.trueman](https://forum.ansible.com/u/clifford.trueman)\
**Post date:** [June 19, 2018, 4:22pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/10 "2018-06-19T16:22:24Z")

</div>

Did you ever get a resolution on this?

---

<div class="post-metadata">

**Author:** ![Nicholas\_Nezis](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Nicholas\_Nezis](https://forum.ansible.com/u/Nicholas_Nezis)\
**Post date:** [July 3, 2018, 8:48pm UTC](https://forum.ansible.com/t/using-sudosh-instead-of-just-sudo/16107/11 "2018-07-03T20:48:56Z")

</div>

No. Sorry.
