• 21st, Jul 2011

SUID to Linux bash or sh scripts

Running scripts / programs as root privileges.

Assign SUID to programs

$ chmod 4755 /home/ipascual/scripts/test.sh

I doesn’t work with shell scripts!!!

Linux doesn’t allow you to use SUID root for shell scripts due to security role. Just real binary programs.
The reason is because an attacker could get the computer to execute any shell script when the script is processing to execute. Because of this, modern linux distributions ignore SUID shell scripts.

The solution is to use “sudo”.

What is sudo?

sudo allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.
But, sudo asks me for the root! My users still can’t use it whiout password.

Running a shell script without asking for root password

$ sudo visudo

# Add this line at the end
ipascual        ALL=NOPASSWD: /home/ipascual/scripts/test.sh

$ cat /home/ipascual/scripts/test.sh
#!/bin/sh
/sbin/shutdown -h now

$ sudo /home/ipascual/scripts/test.sh

Now the user ipascual will execute test.sh as root without password.

Tags: , , ,

One Response to “SUID to Linux bash or sh scripts”


  1. Kmilo
    on Oct 21st, 2011
    @ 12:35 pm

    Nice tip :)

Leave a Reply

*

© 2010 unexpected[it]. All Rights Reserved.