me:2001
incus exec me-workspace --user 2001 -- sh -c 'echo $HOME'
EMPTY
incus exec me-workspace -- sh -c 'echo $HOME'
/root
incus exec me-workspace -- su --login me
me@me-workspace:~$ echo $HOME
/home/me
Why, please?
me:2001
incus exec me-workspace --user 2001 -- sh -c 'echo $HOME'
EMPTY
incus exec me-workspace -- sh -c 'echo $HOME'
/root
incus exec me-workspace -- su --login me
me@me-workspace:~$ echo $HOME
/home/me
Why, please?
For the root user, we can guess what the home directory is (usually /root).
For a random uid provided by the user, we canât do that as we canât resolve the uid to a name without having to run code inside of the container or VM which is unsafe.
I see. What would be the recommended way if I want to run commands dependent on $HOME env var or some other user var? Should I set it manually with --env
? Thanks.
Try using the username instead of uid:
incus exec me-workspace -- sudo --login --user me sh -c "echo $HOME"
Or nest two commands:
incus exec me-workspace -- sudo --login --user $( incus exec me-workspace -- getent passwd 2001 | cut -d: -f1 ) sh -c "echo $HOME"
@qkiel username doesnât work
Error: invalid argument "me" for "--user" flag: strconv.ParseUint: parsing "me": invalid syntax
Nested commands could be a way, but I need to call this from REST API /1.0/instances/{name}/exec
as well. Thanks.
incus query --request POST --wait /1.0/instances/{name}/exec --data â{ âcommandâ: [âshâ, â-câ, âecho $HOMEâ],âenvironmentâ: {âHOMEâ: â/home/meâ}}â
thatâs the commend you want.
Yeah, thatâd be the way to go.