0

Is it possible to write a shell script in which we can include the root commands, and execute it without entering the root password over the terminal.

1

2 Answers 2

0

You can do this by editing your sudoer file.

Open a terminal (ctrl+alt+T)

enter the following command

sudo visudo

Once the file opens enter the following command

username ALL=(ALL) NOPASSWD: /path/to/command

Replace username with the your own username

You can find the path to the command by running

which command

For more information on editing the sudoer file visit this site.

0

Yes.

Some may recommend marking the script as setUID and owned by root. I would discourage this. Instead, put the user under whose ID the script will run into the sudoers group and configure sudo to allow that user to run the specifically required commands as root without requiring that user to enter a password. This provides audibility and keeps things well controlled.

More information on sudo and its configuration can be found here.

3
  • I am going to downvote this as it is a huge security risk and there are several alternate more secure options . From a security perspective, any file that runs all or in part as root should be owned by root and ro or rx by other users without w privilges.
    – Panther
    May 2, 2015 at 22:27
  • Hey @bodhi.zazen, it's generally a better idea to give an account the rights it needs to do something than it is to just be lazy and run things as root. It is better in the long run to create actual separation of duties rather than just fall back on root. This is precisely why so many administrators never log in as anything other than root and fight security management trying to require them to use reduced privilege accounts. May 2, 2015 at 23:40
  • Also, I notice that you didn't downvote the other person recommending precisely what I am. May 2, 2015 at 23:40

Not the answer you're looking for? Browse other questions tagged .