0

EDIT: this Sticky bit enabled Script can't write to a root file appears to be a similar problem

EDIT: How can I use SetUID on a shell script to run as a non-root user? is very similar as well.

I have a script, let's call it read.sh. I have a file, lets call it secret.

# cd /home/normie
# echo "some stuff" > secret
# echo "#!/bin/bash" > read.sh
# echo "cat secret" >> read.sh
# chmod 600 secret
# chmod 4755 read.sh
# su normie
$ ./read.sh
<<Error about not having access to secret>>

Did I miss something? I thought the SUID bit made the script run as the owner? When I run the following

# echo "touch newfile" > sumfile.sh
# chmod 4755 sumfile.sh
# su normie
$ ./sumfile.sh
$ ls -alh
<<newfile shows as owned by root>>

What is going on here, and how do I make it work the way I want? The way I want being, I want regular users to execute a particular script with full root access. (I thought that's what the suid bit did )

FIREBAAT
  • 9
  • 4
  • Does this answer your question? [How can I use SetUID on a shell script to run as a non-root user?](https://serverfault.com/questions/397969/how-can-i-use-setuid-on-a-shell-script-to-run-as-a-non-root-user) – vidarlo Nov 23 '22 at 20:50
  • @vidarlo, mostly. I grabbed some info from other places. – FIREBAAT Nov 23 '22 at 23:54

1 Answers1

-1

Install sudo apt install sudo

Make the relevant users part of some group groupadd group && usermod -g group user

Add the following to /etc/sudoers %group (ALL)=(root:root) NOPASSWD:/path/to/script.sh

Add an alias to .bashrc alias ALIAS='sudo /path/to/script.sh'" >> ~user/.bashrc

All members of group can now run the script in question as root.

Answer shamelessly stolen from How can I use SetUID on a shell script to run as a non-root user? (user9517)

FIREBAAT
  • 9
  • 4
  • Please don't copy answers from Serverfault; rather flag the question as duplicate if you believe another answer can close this question. While the license permits you to copy, it's better to close the question as duplicate. – vidarlo Nov 23 '22 at 20:51
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 07 '22 at 16:46
  • @CommunityBot There's a pattern here of the community ignoring my questions until I answer then myself, then rushing in to down vote me, or providing some meaningless prattle that offers no practical advice, and then circle-jerking each other. Until the community starts delivering some actual value, I really don't care what you think of how I answer my own questions. – FIREBAAT Dec 21 '22 at 18:15