Can I run cloud init as a different user than root?
Asked Answered
E

2

9

I am trying to run cloud init as a different user than root, because of permissions problem when using git. Is there such a way?

Expiate answered 1/11, 2021 at 14:41 Comment(2)
xyproblem.info so the real problem is a permissions thing. You should ask about that problem instead of the problems you have with your chosen solutionPectize
Practically, no. cloud-init expects root privileges for many of the things it tries to do.Tannic
P
8

permissions problem when using git

If trying to run a git command in the runcmd module you could use su to select which user to run the command as.

Consider:

root# su <target user> -c "whoami"
<target user>

I haven't tested it, but something like this in your cloud-config might work:

runcmd:
 - [su, myuser, -c, "git clone <repo> <directory>"]
Pronghorn answered 16/11, 2021 at 14:27 Comment(0)
M
2

To execute a command with non-root user with cloud init, you can do this:

runcmd:
  - su -c 'whoami' - myuser
Marinelli answered 3/5, 2022 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.