LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   /etc/init.d/script.sh permission denied for normal user? (https://www.linuxquestions.org/questions/linux-software-2/etc-init-d-script-sh-permission-denied-for-normal-user-4175442320/)

JZL240I-U 12-20-2012 10:04 AM

/etc/init.d/script.sh permission denied for normal user?
 
I have a script in /etc/init.d (some distros call it /etc/rc.d) where all the other scripts for the runlevels reside. (It minimizes power consumption on a netbook). It gets started during boot all right.

Since not all devices / processes / whatever are up and running I also want to run the script when entering runlevel 5. So I have a link in /home/user/.kde4/Autostart to the original file in /etc/init.d. When I run the script via this link I get "permission denied".

The link has
Code:

lrwxr-xr-x  root root
or
lrwxr-xr-x  me users

and doesn't work.

The script in /etc/init.d has
Code:

-rwxr-xr-x root root
or
-rwxr-xr-x  me users

and doesn't work.

The directories /etc and init.d have "drwxr-xr-x".

No go.

I tried on the script "chmod 1755 script", "chmod 2755 script", "chmod 3755 script", "chmod 5755 script", "chmod 7755 script" -- nothing (as you see, I don't really understand the effects, but I tried).

Why doesn't it work?

unSpawn 12-20-2012 11:37 AM

Quote:

Originally Posted by JZL240I-U (Post 4853762)
Why doesn't it work?

For one because you seem to be doing things without understanding the consequences and that's the way to fsck up your system good. Also system services are run for the system and unprivileged users shouldn't manage those.
- If the service should run in runlevel 5 then use your system management tools (or add a slink) to make it start in runlevel 5.
- If the service restart depends on device availability then check Udev or whatever your system uses to trigger a response.
- If you need the user to run the service anyway then add an entry for the exact command in /etc/sudoers and configure it so the users can execute the exact command though Sudo without it asking for a password for it.
- If you want to do the above but in a less DE-dependent way you could try using pam_script in the PAM stack for GDM, KDM or whatever DMs you have.

JZL240I-U 12-21-2012 02:21 AM

Quote:

Originally Posted by unSpawn (Post 4853796)
For one because you seem to be doing things without understanding the consequences...

Exactly. An that is what I wrote. But I think the risk is manageable, the machine is not in any net and I reset the permission imediately after the test. I also read up on setuid and guid.

Quote:

Originally Posted by unSpawn (Post 4853796)
- If the service should run in runlevel 5 then use your system management tools (or add a slink) to make it start in runlevel 5.

That is what I did. And it works. Like I wrote in the first post.

It is not a service in the usual sense but a script which runs just once to minimize power consumption of the system.

Quote:

Originally Posted by unSpawn (Post 4853796)
- If the service restart depends on device availability then check Udev or whatever your system uses to trigger a response.

It is udev. I know how to write a rule but not how to "check" udev "to trigger a response". Do you have a good source so I can read up on that?

Quote:

Originally Posted by unSpawn (Post 4853796)
- If you need the user to run the service anyway then add an entry for the exact command in /etc/sudoers and configure it so the users can execute the exact command though Sudo without it asking for a password for it.

Good idea. The reason I did it the way I described in the first post is that I wanted to have only one version of the script in one place (/etc/init.d). And I wanted to start it automatically.

Quote:

Originally Posted by unSpawn (Post 4853796)
- If you want to do the above but in a less DE-dependent way you could try using pam_script in the PAM stack for GDM, KDM or whatever DMs you have.

Another good idea. But this is a netbook just for taking notes etc. when I'm travelling, so I'll use a DE (KDE). Not to mention the fact that I would have to do an other massive amount of learning ;).

But ... my original question is not really answered: Why doesn't it work? This is something I'd very much like to understand.

unSpawn 12-21-2012 03:15 AM

Quote:

Originally Posted by JZL240I-U (Post 4854178)
It is not a service in the usual sense but a script which runs just once to minimize power consumption of the system.

...and the actual command(s) the script runs requires root privileges, is the reason why.

JZL240I-U 12-21-2012 04:58 AM

....ahhh, I see -- and should have seen earlier. Thanks unSpawn.

The script has tons of write operations on files writeable only to root. While I might change all necessary permissions sequentially by hand, I would also have to keep track of them during system updates. That is too much ado. I'll use sudo when there is no connection to the power grid. Issue solved. Thanks again.

P.S.: ...that source to read up on udev triggers? ;)

unSpawn 12-21-2012 05:13 AM

Quote:

Originally Posted by JZL240I-U (Post 4854244)
P.S.: ...that source to read up on udev triggers? ;)

What's that popular search engine called again?

*If it's about a device connect / disconnect thing maybe post some lsusb / lspci / lshal / ls*whatever specs? Else a verbose description of what's happening.

JZL240I-U 12-21-2012 05:20 AM

Okay, okay, okay ;). "udev trigger" gives plenty of results, I'll learn from them. I thought you had something special in mind.


All times are GMT -5. The time now is 07:35 AM.