Remove Shutdown, Suspend, Restart, and Hibernate from the user switcher menu

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.


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.


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]
Identity=unix-user:*
Action=org.freedesktop.upower.suspend
ResultActive=no

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]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=no

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