2

I have used gksu -w shutdown -hP now as a system-wide menu command in icewm, so that when a non-admin user clicked the shutdown from the menu, a password dialogue box will appear asking for the admin password. That was when I was running icewm in Linux Mint.

When I switched to Ubuntu, the same command wouldn't work. Although the same dialogue box asking for admin password appears, but none of the existing sudoers password I tried would work or accepted. Even the password of the first account I was asked to make on installation of Ubuntu wouldn't work.

I have also tried gksu -u admin-user -w 'shutdown -hP now, but the error message "shutdown: Need to be root" came up.

So what is the difference between Ubuntu's and Mint's gksu rules? I'm currently using Ubuntu 12.04 LTS, and the Mint I'm referring to is Mint 13 Maya. And what could be other alternative ways to allow a Shutdown command in the IceWM menu for non-admin users, but I still want them to ask permission first from me before they could shutdown, by asking for my admin password?

Besides shutdown, I also have other commands in the IceWM menu that require admin privileges, like hibernate, to mount a backup partition, and synaptic, which I applied gksu -w with.

karel
  • 110,292
  • 102
  • 269
  • 299
  • Since its asking for the password, I'd just check to see the output of the command. Try `gksu -w shutdown -hP now > /tmp/gksu-output` and see what it says. That might be the best way to find out why its not working. – Fahad Yousuf Aug 26 '13 at 01:14
  • I just tried ...same thing, 'didn't accept the admin-user password, and it did not say anything. The file /tmp/gksu-output is empty, when I opened it. – Joseph Domingo Tibi Ensano Aug 26 '13 at 01:53
  • Are you sure the user you are using is in the admins and sudo group? You may want to add it to those groups using `sudo usermod -G admin` and `sudo usermod -G sudoers` and try again. – Fahad Yousuf Aug 26 '13 at 10:58
  • No, the user shouldn't be in the sudo group. It really happens in Mint, where a standard user uses this command and a dialogue box asking for the administrator password appears, then I supply any of the administrators' password, and it works. I just can't figure that out here in Ubuntu. But I like it here in Ubuntu, 'coz programs runs more responsive and quicker. – Joseph Domingo Tibi Ensano Aug 26 '13 at 11:09
  • ok. i got something... I tried using "gksu -u admin -w gksu 'shutdown -hP now'", and it worked. I was able to shutdown the computer while logged as a standard user. the only setback is that it now asks administrative password twice. So how do I make it to ask admin password only once? users might think i'm too paranoid...LOL :D – Joseph Domingo Tibi Ensano Aug 26 '13 at 13:30

2 Answers2

2

The problem:

  • gksu -w will ask for your root password, however the root user does not have a password by default in Ubuntu, so everything you try will fail.

  • gksu -u admin-user -w will execute shutdown as admin-user, but you need to be root, not admin-user.

The possible solutions are two:

  1. Use gksu -u admin-user -w gksu -S. Which means: first switch to admin-user (gksu -u admin-user -w), then become root (gksu -S).

  2. Set a password for the root user. This way, gksu -w will work as you expect.

The drawback for the first solution is that you will be asked for two passwords, which may be uncomfortable. The drawback for the second solution is that enabling the root user is not recommended.

Andrea Corbellini
  • 15,616
  • 2
  • 64
  • 81
  • Gee! Thanks, Andrea! Does that mean that in Mint they set a password to root? Now, I'll be able to add the system-wide rootmenu options on our icewm, that are admin-access only. Thanks again and God bless. – Joseph Domingo Tibi Ensano Aug 26 '13 at 14:09
  • @JosephDomingoTibiEnsano: I'm not a Mint expert, however Googling it seems that yes: they set a root password. – Andrea Corbellini Aug 26 '13 at 14:15
  • Isn't it possible to add special priviledges for sudo, just for the shutdown commands precisely? It actually is if you wish. This way, `sudo` (and `gksudo`, `gksu` and other similar ones) will allow those commands directly. – Paul Stelian Apr 18 '16 at 19:54
  • (although it seems that in the question the real problem is a polkit misconfiguration, that is, the priviledges for shutdown/... are not used, or icewm is not made aware of policykit) – Paul Stelian Apr 18 '16 at 19:55
  • 1
    @PaulStelian: yes, indeed. You have to edit the sudoers file (using `visudo`) and add a line like this: `user ALL=(ALL) NOPASSWD: /sbin/shutdown`. You can even add arguments if you want the rule to be more restrictive – Andrea Corbellini Apr 19 '16 at 07:34
0

I would reccommend using gksudo and not gksu although they aren't very different in Ubuntu. Just add the 'admin-username' to the 'sudoers' or 'admin' group or just give it access to the shutdown command in the /etc/sudoers file.

Then instead of gksu -w <admin-username> <command> you could use gksudo <command>. Again the whole point of having sudo/gksudo is to have users be able to do administrative tasks without giving them full blown root access.

Fahad Yousuf
  • 1,144
  • 7
  • 12