Permission Issues, Not Able to Run Script as Root

Permission issues, not able to run script as root

Make sure that your partition is not mounted with the noexec flag (which - as the name suggests - prevents making any files executable)

Unable to execute bash scripts even as root?

That can happen if you have mounted the file system with the "noexec" option. You should remove it.

shell script run when I am root but I get a permission denied when it is invoked from a Makefile (still as root)

In your comments above you say when you "run it manually" you use . scriptname.sh, is that correct? You use . followed by scriptname.sh?

That does not run the script, that sources the script. Your statement that scriptname.sh will execute with and without the x permission since it is a shell script is wrong. You can source the script if you have read permissions. But you cannot execute the script unless you have execute permissions.

"Sourcing" means that a new shell is not started: instead your current shell (where you type that command) reads the contents of the script and runs them just as if you'd typed them in by hand, in the current shell. At the end all the side-effects (directory changes, variable assignments, etc.) that were performed in that script are still available in your current script.

"Executing" means that the script is treated like a program, but the program is a new shell that's started, which then reads the contents of the script and executes it. Once the script ends the shell exits and all side-effects are lost.

The $(shell ...) function in make will not source your script (unless you also use . there, which you did not). It will try to run your script. The error you show implies that either systype.sh did not have the execution bit set, or else that it had an invalid #! line. There's no other explanation I can think of.

If sourcing the file really does what you want then why not just use the same method in $(shell ...) that you use in your own personal use:

PLATFORM=$(shell . $(ROOT)/systype.sh)

If changing the user permission didn't work, are you sure that whatever user owns the script is the same user you're using to invoke make? You say you're "running as root"; is the script owned by root? Or is it owned by you and you're running sudo make or similar?

I don't know why you don't just use:

chmod +x systype.sh

and call it a day.

How can I let users run a script with root permissions?

You could consider sudo.

Although not 'passwordless', it doesn't require the user to be given the root password. It can also provide an audit trail of use of the script.

edit: as per comment from Chris, there is an option not to require a password at all for certain commands, see here for details. It can also be set up not to prompt excessively for the password, i.e. one entry of the password can be good for multiple commands over a period of use.

By the way, sudo is built in to Ubuntu and nicely integrated with Gnome. When ubuntu prompts you for your password to do privileged operations, that's sudo under the hood.



Related Topics



Leave a reply



Submit