Score:1

Executing a script under a specific user

in flag

I have a script which runs as root (azure CustomScript vm extension) which launches another script (not maintained by me) that should configure a particular service to run under specific user (the user that the script was invoked by).

working dir /downloads/0

drwx------ 3 root root 4096 Oct 6 08:50 0

myscript.sh (run as root by vm extension)

#!/bin/bash
curl https://raw.githubusercontent.com/MicrosoftDocs/mslearn-azure-pipelines-build-agent/main/build-agent.sh > build-agent.sh
chmod u+x build-agent.sh
sudo -E -u myuser./build-agent.sh 

In theory this should achieve what I want, but my problem is that I get

sudo: unable to execute ./build-agent.sh: Permission denied

I have tried:

chown myuser build-agent.sh
chmod u+x build-agent.sh
sudo -E -u myuser ./build-agent.sh 

still got Permission denied, how do I configure permissions for this? permissions after the last command:

ls -l build-agent.sh
-rwxr--r-- 1 opsai root 1731 Oct  6 11:02 build-agent.sh
sudodus avatar
jp flag
1. Please show us the permissions and ownership of `build-agent.sh`. Edit the original question to add the output of `ls -l build-agent.sh`; 2. Can you add permissions to the working dir or if that is not possible, can you create a new working directory, where the standard user has read, write and execute permissions?
Aurimas N. avatar
in flag
```shell ls -l build-agent.sh -rwxr--r-- 1 myuser root 1731 Oct 6 11:02 build-agent.sh ``` working dir is temporary subdirectory where the stuff is being downloaded, so I guess there is no harm in changing permissions there, I guess creating new dir and `cd`ing there is also an option if that makes any difference. @bac0n just a typo
sudodus avatar
jp flag
Are you using `opsai` instead of `myuser` ? Anyway, I think it will work when you add permissions to the working directory.
Aurimas N. avatar
in flag
forgot to replace that when editing text, but there is only one user and let's refer to it as "myuser".
sudodus avatar
jp flag
OK - I was just checking (it is easy to forget such obvious things).
Aurimas N. avatar
in flag
changing owner on working dir worked, thanks.
sudodus avatar
jp flag
You are welcome. I'm glad that I could help you find a solution :-)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.