run bash as root in wsl

84 views
Skip to first unread message

Andy Bergh

unread,
Sep 16, 2021, 7:03:53 AM9/16/21
to go-cd

Hi,

I installed gocd on wsl (not wsl2) on windows server 2019.

When a job in a stage runs (test.sh for example), the bash file is run as user 'go'.
Is there a way for me to run the bash file as user root?

I have been trying to find ways around it but run in so many other problems. Like ssh keys, access to servers (from within the bash script) etc.

This will be much easier if I can somehow make gocd run the bash file as root in wsl.

Is this possible?

Thanks

Jason Smyth

unread,
Sep 16, 2021, 11:04:36 AM9/16/21
to go-cd
Hi Andy,

I have never tried running Agents inside WSL (or WSL2) but my guess is that the script will run as whatever account the Go Agent service runs under.

So if you want the script to run as root there are a few options:

1. Run the Go Agent service as root,
2. Grant the "go" user permission to run the script as root via sudo, either with password or without, or
3. Set the script owner to "root" and set the sticky bit so that whenever _anybody_ runs the script it runs as root. (This is probably only viable if the script is a permanent fixture inside the WSL installation. If the script is pulled from elsewhere at runtime then it will be owned by the "go" user and this just moves the problem around, forcing you to find a way to run chown and chmod as root instead of the script itself.)

Hope this helps,
Jason

Andy Bergh

unread,
Sep 16, 2021, 12:16:19 PM9/16/21
to go-cd
Hi Jason,

Thank you for the email.

I basically do everything as root in the wsl (it's a safe environment :D). I start the server and agent as root (installed gocd as root as well), the script owner is root ect.
I double checked these and still if I print "whoami" when the script is executed as a job by gocd the output is 'go'.

I have since been able to find a workaround for my root problem so no need for anyone reading this email to spend time on it.

It would be nice though to have jobs in gocd on Linux run as root - or a selected user. I find it extremely odd that this is not a query that is quite common (I did a basic search).

In any event, gocd is working great!

Thank you

--
You received this message because you are subscribed to a topic in the Google Groups "go-cd" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/go-cd/KzKw8hudN5s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to go-cd+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/go-cd/ae4863bd-ae81-4052-b325-7c34f05bab70n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages