I'm on Ubuntu 20.04 and trying to run a command as root, but without using sudo and instead using the sticky bit.
I've read this answer but can't seem to get it to work.
I've created a script called whoami_root
to show the user that it is running as.
Output of cat whoami_root
:
#!/bin/bash
whoami
I have run sudo chown root whoami_root
and sudo chmod u+s whoami_root
Output of ll whoami_root
:
-rwsr-xr-x 1 root root 20 Nov 6 23:33 whoami_root
Output of ./whoami_root
myuser
Why does it seem to ignore the suid bit and run as myuser instead of root?
The setuid bit is ignored for interpreted programs like shell scripts.
See https://unix.stackexchange.com/a/2910/330217
If
whoami
is a binary executable, you can create a copy of this program and set thesetuid
bit.You can configure
sudo
to allow running a specific command asroot
without asking for a password.