1

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.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
rori
  • 11
  • 2

1 Answers1

6

Creating a su root bash script is dangerous. 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.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47