I'm using a desktop as both a router for my local network and as a normal desktop with multiple users. I have Maverick running on it. Occasionally, one of the desktop users will accidentally press Shutdown, Restart, Suspend, or Hibernate, leading to me having to fix the network at random times of day. I know how to restart and shutdown from the command line. I do not need the GUI interface.

How can I remove the Shutdown, Suspend, Restart, and Hibernate options form the user switcher menu? All the I want left is the "Lock Screen", "Guest Session", List of users and "Logout" left.

A system wide solution would be best, but I can do one on each user if necessary.

  • If you do find away to just take those options out of the gui . Then it would cure your issue. But It will be very tedious and risky. What i would be afraid of is making this change and leaving the system unable to restart even from the command prompt. – freebird Jul 16 '11 at 6:34
  • 1
    @freebird I'm sorry but I can't agree with your comment. A GUI option to shutdown isn't mandatory. Servers, mostly, don't run a desktop env like GNOME and can restart at will – sergio91pt Jul 16 '11 at 9:21
  • Latest workaround for Ubuntu 17.04 can be found in this post, which suggests to modify files under /usr/share/polkit-1/actions. But this may be overwritten by updates. P.S.: I may post a different answer for Ubuntu 16.04 later. – clearkimura Sep 13 '17 at 18:14

Option 1:

Install gconf-editor, run gksu gconf-editor and on /apps/indicator-session/ supress the restart and shutdown.

I'm not sure about suspend and hibernate, maybe changing <allow_active> to no on /usr/share/polkit-1/actions/org.freedesktop.upower.policy will do the trick.

Option 2:

Remove the Indicator session package and add desktop shortcuts to logout and locking the screen.

The command to logout is gnome-session-save --logout-dialog and to lock the screen use gnome-screensaver-command --lock.

| improve this answer | |
  • 1
    The first option works. I'm not sure if you can still suspend or hibernate from the CLI with it, but that doesn't really matter on this machine. Thanks! – Azendale Jul 16 '11 at 16:49

For Ubuntu 14.04 and 16.04 (Unity)

Use gsettings to disable most of menu items in indicator session menu and use systemctl to disable suspend ability itself at systemd level. This solution is not perfect, though.

How to disable menu items

To begin with, look for relevant keys using gsettings command and filter with grep command. Use "session" and "menu" for keywords to filter twice.

$ gsettings list-recursively | grep session | grep menu
com.canonical.indicator.session suppress-logout-menuitem false
com.canonical.indicator.session force-restart-menuitem false
com.canonical.indicator.session suppress-restart-menuitem false
com.canonical.indicator.session suppress-shutdown-menuitem false
com.canonical.indicator.session user-show-menu true

Then, use gsettings to set relevant keys with value that is opposite to current values i.e. "false" becomes "true", vice versa. Run the following commands, one by one.

$ gsettings set com.canonical.indicator.session suppress-shutdown-menuitem true
$ gsettings set com.canonical.indicator.session suppress-restart-menuitem true
$ gsettings set com.canonical.indicator.session suppress-logout-menuitem true
$ gsettings set com.canonical.indicator.session user-show-menu false

For suppress-logout-menuitem key to take effect, user may need to reload Unity desktop (run unity command in Terminal or HUD command prompt, no need to log out or anything).

And that is all needed to do for hiding most of menu items.

Before and after disabling menu items in indicator session

Following above steps, all menu items are now hidden in indicator session menu except for "Suspend" menu item. There is an open bug regarding the inability to hide the Suspend menu item. Confirming and subscribing to it may encourage it's resolution.

Given that the menu item cannot be suppressed directly, the next easiest solution is to disable any suspension at system-wide level.

How to disable suspend in Ubuntu 14.04 (Unity, upstart)

In 14.04 release, there are several ways to disable suspension i.e. edit configuration files for polkit-1 or pm-utils. But there is no clarification of which will actually work properly.

How to disable suspend in Ubuntu 16.04 (Unity, systemd)

In 16.04 release, disable any suspension with systemd as noted on Debian Wiki.

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink from /etc/systemd/system/sleep.target to /dev/null.
Created symlink from /etc/systemd/system/suspend.target to /dev/null.
Created symlink from /etc/systemd/system/hibernate.target to /dev/null.
Created symlink from /etc/systemd/system/hybrid-sleep.target to /dev/null.

The systemctl command will take effect immediately. No need to reboot or anything.

As a result, whenever the "Suspend" menu item is clicked, the system does not go to sleep but only cause the screen to turn blank and returned to login screen (similar effect to "Lock Screen").

Workaround for known issue after suspend

Even without actual suspension, the same known issue will arise when resuming current session: Network manager does not wake up after suspend. The workaround is to restart the service.

$ sudo systemctl restart network-manager.service

The network manager will be restarted and networking will be available again.

Tested all above working in Ubuntu 16.04 (Unity), fresh installed in VirtualBox.

  • 1
    Interesting. It's odd that there is no key for suspend, but just shutdown, restart, logout, and the user menu. – Elder Geek Sep 14 '17 at 23:13
  • 1
    Related post: How to disable suspend in 14.04?. I don't have Ubuntu 14.04 so I can't test this from my side. Although, I have added relevant text that could be replaced later by anyone who want to improve the answer. – clearkimura Sep 16 '17 at 13:29

For suspend and hibernate, instead of editing a package file that will be replaced when the package is updated, one can use files in /etc/polkit-1/localauthority. Disable suspend with the file /etc/polkit-1/localauthority/90-mandatory.d/disable-suspend.pkla containing :

[Disable suspend]

This is inspired by the file /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla containing, among other things, the configuration to disable hibernation :

[Disable hibernate by default]

At least, it's what I use on Ubuntu 12.04.

More on PolicyKit local authority: http://hal.freedesktop.org/docs/polkit/pklocalauthority.8.html

| improve this answer | |
  • Does not work in 13.10 – Takkat Mar 30 '14 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.