# Run Chef in another user

**URL:** <https://discourse.chef.io/t/run-chef-in-another-user/5630>\
**Category:** Chef Infra (archive)\
**Created:** [August 13, 2014, 1:30pm UTC](https://discourse.chef.io/t/run-chef-in-another-user/5630 "2014-08-13T13:30:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ana\_Ferreira](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Ana\_Ferreira](https://discourse.chef.io/u/Ana_Ferreira)\
**Post date:** [August 13, 2014, 1:30pm UTC](https://discourse.chef.io/t/run-chef-in-another-user/5630/1 "2014-08-13T13:30:59Z")

</div>

hello,

I’m trying to deploy a software tha has to be install in a expecific user

when I try this, the user doesn’t change(stays root).

execute ‘install\_scos’ do  
cwd '/home/S2K’  
command "/opt/platform3pp/MICONYS/SCOS/S2K-5-5-1-issue-1/installMission.PARC  
-c=Single -p=Standalone\_single -z=Multi  
/opt/platform3pp/MICONYS/SCOS/S2K-5-5-1-issue-1/SDCF\_MCNYS61.xml"  
user 'S2K’  
group 'users’  
action :run

Is there a way that i can why chef login in another user., and run commands in  
there?  
this has to be done in that user because it uses a diferente shell (tcsh).

---

<div class="post-metadata">

**Author:** ![werebus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/werebus/32/24_2.png) [@werebus](https://discourse.chef.io/u/werebus)\
**Post date:** [August 13, 2014, 1:54pm UTC](https://discourse.chef.io/t/run-chef-in-another-user/5630/2 "2014-08-13T13:54:55Z")

</div>

Hey Ana,

execute uses mixlib-shellout [https://github.com/opscode/mixlib-shellout](https://github.com/opscode/mixlib-shellout)  
under the hood, which in turn (on Unix-y platforms) forks and sets the uid  
[https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/unix.rb#L122-L127](https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/unix.rb#L122-L127)  
of the child process. So, it does run the command “as” the specified user,  
but it doesn’t “log in” as that user. If what you need is for your command  
to run under tcsh as that user, you could use the script resource  
[http://docs.getchef.com/resource\_script.html](http://docs.getchef.com/resource_script.html) and specify an interpreter,  
I think.

I notice that Chef actually has a “csh” resource  
[http://docs.getchef.com/resource\_csh.html](http://docs.getchef.com/resource_csh.html) which might do the trick (since  
tcsh is csh-compatible).

Matt Moretti  
​

On Wed, Aug 13, 2014 at 9:30 AM, [anasofia1072@gmail.com](mailto:anasofia1072@gmail.com) wrote:

> hello,
> 
> I'm trying to deploy a software tha has to be install in a expecific user
> 
> when I try this, the user doesn't change(stays root).
> 
> execute 'install\_scos' do  
> cwd '/home/S2K'  
> command  
> "/opt/platform3pp/MICONYS/SCOS/S2K-5-5-1-issue-1/installMission.PARC  
> -c=Single -p=Standalone\_single -z=Multi  
> /opt/platform3pp/MICONYS/SCOS/S2K-5-5-1-issue-1/SDCF\_MCNYS61.xml"  
> user 'S2K'  
> group 'users'  
> action :run
> 
> Is there a way that i can why chef login in another user., and run  
> commands in  
> there?  
> this has to be done in that user because it uses a diferente shell (tcsh).

---

<div class="post-metadata">

**Author:** ![Ana\_Ferreira](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@Ana\_Ferreira](https://discourse.chef.io/u/Ana_Ferreira)\
**Post date:** [August 13, 2014, 2:42pm UTC](https://discourse.chef.io/t/run-chef-in-another-user/5630/3 "2014-08-13T14:42:59Z")

</div>

Hello Matt

thank for you reply.  
i finded very helpfull!  
I could already find the sulotion for my problem.

ty

On Wed, Aug 13, 2014 at 2:54 PM, Matthew Moretti [werebus@gmail.com](mailto:werebus@gmail.com) wrote:

> Hey Ana,
> 
> execute uses mixlib-shellout [https://github.com/opscode/mixlib-shellout](https://github.com/opscode/mixlib-shellout)  
> under the hood, which in turn (on Unix-y platforms) forks and sets the uid  
> [https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/unix.rb#L122-L127](https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/unix.rb#L122-L127)  
> of the child process. So, it does run the command “as” the specified user,  
> but it doesn’t “log in” as that user. If what you need is for your command  
> to run under tcsh as that user, you could use the script resource  
> [http://docs.getchef.com/resource\_script.html](http://docs.getchef.com/resource_script.html) and specify an  
> interpreter, I think.
> 
> I notice that Chef actually has a “csh” resource  
> [http://docs.getchef.com/resource\_csh.html](http://docs.getchef.com/resource_csh.html) which might do the trick  
> (since tcsh is csh-compatible).
> 
> Matt Moretti  
> ​
> 
> On Wed, Aug 13, 2014 at 9:30 AM, [anasofia1072@gmail.com](mailto:anasofia1072@gmail.com) wrote:
> 
> > hello,
> > 
> > I'm trying to deploy a software tha has to be install in a expecific user
> > 
> > when I try this, the user doesn't change(stays root).
> > 
> > execute 'install\_scos' do  
> > cwd '/home/S2K'  
> > command  
> > "/opt/platform3pp/MICONYS/SCOS/S2K-5-5-1-issue-1/installMission.PARC  
> > -c=Single -p=Standalone\_single -z=Multi  
> > /opt/platform3pp/MICONYS/SCOS/S2K-5-5-1-issue-1/SDCF\_MCNYS61.xml"  
> > user 'S2K'  
> > group 'users'  
> > action :run
> > 
> > Is there a way that i can why chef login in another user., and run  
> > commands in  
> > there?  
> > this has to be done in that user because it uses a diferente shell (tcsh).
