0

i want that my all users can run a bash script. But this bash script need to have root right, i want that this script is in read only and run with root right

my bash script :

#!/bin/bash
/sbin/swapoff -a

in my search i found solution but it not work, this is solution :

# chown root:root monshell.sh
# chmod 4755 monshell.sh
# exit
$ ./monshell.sh

but i have this error when i run with basic user : swapoff: Not superuser.

5

Creating a su root bash script is bad practice. A bash script is too easy to manipulate in ways you don't expect to run other commands. Every new su root executable is a new security risk.

The preferred way to grant rights like this is with sudo. Create a file /etc/sudoers.d/swapoff, as follows:

ALL ALL = /bin/swapoff -a

Then all users (the first ALL) on all hosts (2nd ALL) may run sudo /bin/swapoff -a. And each time they do that, it will be logged to syslog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.