1

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?

steeldriver
  • 142,475
localhost
  • 254

1 Answers1

1

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 the setuid bit.


You can configure sudo to allow running a specific command as root without asking for a password.

Bodo
  • 591