Ezra T
Ezra T

Reputation: 89

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

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?

Upvotes: 9

Views: 6661

Answers (2)

Brett Holman
Brett Holman

Reputation: 857

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>"]

Upvotes: 8

ethicnology
ethicnology

Reputation: 606

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

runcmd:
  - su -c 'whoami' - myuser

Upvotes: 2

Related Questions