Run shell provisioning script as custom user

Hi all,

I would like to run a shell provisioning script as a custom non-privileged user.

If I use something like this:

# Vagrantfile
config.vm.provision "shell", path: ""

sudo su - bob

the user does not change to bob, it's root:

default: uid=0(root) gid=0(root) groups=0(root)
default: root

Why it doesn't work? It works fine when I ssh to my box.

I could switch to user bob when I use a script from the sync folder calling it inside of an inline block, but I would like to do it without putting anything into the sync folder.

Any ideas?

1 thought on “Run shell provisioning script as custom user”

  1. sudo su – bob

    starts a new shell interactive shell, but there’s no input, so the shell (the `sudo` command) ends. The parent `` shell then continues.

    You might want to create a separate `` and start it from the `` script. And plain `su` will do:

    su – bob -c ./

    trying this out in a shell would have given the same result


Leave a Comment