When spinning up an AWS or other cloud vendor instance, and using cloud-init to configure the host, what user do bash scripts that get called run as?
What user does cloud-config run as?
Asked Answered
Building an instance with the following config:
#cloud-config
write_files:
- path: /root/test.sh
content: |
#!/bin/bash
set -x
set -e
whoami
runcmd:
- bash /root/test.sh
I got an output of:
+ whoami
root
Ubuntu cloud-config runs as root.
Is it possible to set a custom user? –
Muslin
@RovshanMusayev runuser -l $USER -c "<COMMAND" –
Blavatsky
It seems to me like a hack, but not a native cloud-init feature. I am not only about running a command but also running whole cloud init including writing files with custom user –
Muslin
I'm not sure it is possible. However, if it is possible and someone knows how to do it, I would love to learn. –
Belligerent
@RovshanMusayev As far as files go, you can write those files as root user, and after that
chown
them to whatever user you need to. –
Lobe © 2022 - 2024 — McMap. All rights reserved.