How to run a script as sudo in lxd container from host console

I have a bash script that i have to run inside my container as user ‘myself’

On host this work good but it will execute script as root.
lxc exec c1 – /bin/bash -c " . /"

I want to run this script as user -‘myself’

My try First:
lxc exec c1 -- /bin/bash -c " su myself && sudo . /"
( I get inside container as myself but the next part to run ./ doesn’t work)


Second try:
lxc exec c1 -- sudo --login --user myself && sudo . /
same thing …


Is it possible to run a script inside lxd container from host as a user of lxd container?

Well you might try this:

lxc exec mycontainer -- sudo --login --user myself sudo myself [path to script]

because sudo is a command, you can simply use it as if you use other commands.

But I don’t know about the syntax after the second “sudo”, maybe the arguments (myself [path to script]) for sudo need to be written in a different way :thinking:.