LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Allow unprivileged users to change runlevel (http://www.linuxquestions.org/questions/linux-software-2/allow-unprivileged-users-to-change-runlevel-625192/)

TexasDex 03-02-2008 02:45 PM

Allow unprivileged users to change runlevel
 
I have a Gentoo server that I occasionally have users who also need to use it as a desktop. Although it's not terribly short on RAM I don't like to have the X desktop running unless it's really needed, so the initdefault is 3. However I have unprivileged users who need to be able to start X (as well as ALSA services) by changing to runlevel 5.

A simple SUID script would theoretically work, but of course when I make one and try to execute it, the shell doesn't execute it directly, instead executing the interpreter (which has normal permissions) with the suid script as an argument, meaning the suid bit has no effect.

I just need a simple way for users to change to runlevel 5 without giving them root access. I've even tried compiling a tiny SUID C program that runs system("/sbin/init 5"); but it doesn't work and I'm not sure why.

I know I could do this easily with Sudo but I don't want to install that if I don't have to, because the machine already has more junk on it than I'd prefer. Is it possible to do this without it, or should I just suck it up and emerge sudo?

tredegar 03-02-2008 03:31 PM

Have you tried just booting to runlevel 5 ?

X will be started, and if I understand correctly not usually be used on your system.

If memory is tight, the kernel will send it to swap if noone is using it: No significant performance hit, apart form the kernel saying "I need some more RAM, what isn't being used..... X, so I'll swap it out".
When your user(s) need it, it'll be swapped back in. A few milliseconds. Who cares?

Try allowing the kernel to do what it was designed to do: manage the available reources for you :)

Do benchmarking if you like.

marco18 03-02-2008 03:34 PM

Maybe it isn't necessary to switch runlevel. You could try stopping the X server. Anyway, I don't remember if that also needs priviliges to be run.

PTrenholme 03-02-2008 03:38 PM

Let then log in at level 3 and do a startx. The only difference is that level 3 is a single user mode, and, if you only have one user at a time running, that's not a limitation.

Oh, you could set up a .bashrc for them so that startx would run automatically as soon as they logged in.

moljac024 03-02-2008 04:45 PM

Or just have two GRUB entries, one with init level 3 and one with init level 5

For example:


Code:

title  Your Linux (runlevel 5)
root  (hd0,0)
kernel /vmlinuz26 root=/dev/sda6 ro 5
initrd /kernel26.img

title  Your Linux (runlevel 3)
root  (hd0,0)
kernel /vmlinuz26 root=/dev/sda6 ro 3
initrd /kernel26.img


AceofSpades19 03-02-2008 04:49 PM

Quote:

Originally Posted by PTrenholme (Post 3075979)
Let then log in at level 3 and do a startx. The only difference is that level 3 is a single user mode, and, if you only have one user at a time running, that's not a limitation.

Oh, you could set up a .bashrc for them so that startx would run automatically as soon as they logged in.

run level 3 is multi-usermode
run level 1 is single user

chrism01 03-02-2008 06:15 PM

sudo is tiny.
It's also the best way to allow non-root user's to do anything you specify. I'd go with that.

TexasDex 03-02-2008 08:23 PM

tredegar has a good point, that it probably doesn't hurt all that much as long as I have enough swap. PTrenholme has a pretty good idea too, I probably should have thought of that, but I think I want a full desktop manager (xdm, in keeping with the minimalism, and I only have IceWM twm, and mwm installed). But chrism01 is right too, that sudo is small so I just stuck that on. I had thought about using grub, a'la moljac024's solution, but decided that I didn't want them rebooting my server whenever they wanted a desktop. So sudo it is. Thank you all!

PTrenholme 03-03-2008 08:16 AM

Quote:

Originally Posted by TexasDex (Post 3076190)
tredegar has a good point, that it probably doesn't hurt all that much as long as I have enough swap. PTrenholme has a pretty good idea too, I probably should have thought of that, but I think I want a full desktop manager (xdm, in keeping with the minimalism, and I only have IceWM twm, and mwm installed). But chrism01 is right too, that sudo is small so I just stuck that on. I had thought about using grub, a'la moljac024's solution, but decided that I didn't want them rebooting my server whenever they wanted a desktop. So sudo it is. Thank you all!

I believe that startx starts the X-server, invokes the display manager (xdm, gdm, kdm, etc.), and then the DM starts the window manager. So having the user log in at level 3 (O.K. AceoSpades19, I misspoke. :eek:) doesn't mean that you won't have a DM running after a startx.

The only "problem" with my proposed solution is that you can only exit the X-windows session to the session from which startx was run, so the user would need to do an exit, reboot or shutdown by hand when they terminated the X session.

I'm fairly familiar with the technique since I often need to use it when I boot Fedora from a USB drive on a non-Linux system, and the device drivers aren't set up properly for the "strange" hardware. So startx sometimes fails -- although, more often than not, it finds a driver in its list that does work -- and I need to "tweak" xorg.conf in the Midnight Commander editor to get it to work. Whilst "tweaking," I save the changed xorg.conf file and then try startx 'till I get it working.


All times are GMT -5. The time now is 12:05 AM.