4

I am looking for a terminal command to shutdown without having to write down my password and without installing any extra programs.

As when clicking the shutdown button, why it is not asking me for the password and a program like gnome-pie that shutdown without asking me for the password and without confirmation.

I want this command as I am a Java programmer and I want to make use of it.

enzotib
  • 93,831
Black Block
  • 4,991

3 Answers3

5

You will need to add command alias for all related command as follows:

Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/halt, /sbin/reboot

and after that you need to add a user specification as follows at the end of /etc/sudoers file

<your username> ALL=(ALL) NOPASSWD: SHUTDOWN_CMDS

You will need root permissions to write to sudoers file.

This is from ubuntu community documentation at https://help.ubuntu.com/community/Sudoers#Shutting_Down_From_The_Console_Without_A_Password

binW
  • 13,034
0

You could make your 'sudo' work without a password.

visudo

Add to end of the file...

your_user_name ALL = NOPASSWD: ALL

Save. Log out. Log in. Now you can shutdown/reboot without a password. But I think you want this link instead: How can I make shutdown not require admin password?.

  • 1
    I dont think that removing password for all commands is a good idea. It will have almost all the same disadvantages/problems that logging as root user has. I would recommend creating an alias for all related commands and using NOPASSWD for that alias only. – binW Dec 08 '11 at 14:39
0

Assuming you want to run the commands under an X session:

Under UPower (Ubuntu 10.04+)

to suspend:

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend

to hibernate:

dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Hibernate

You can find more info at: https://wiki.ubuntu.com/DebuggingGNOMEPowerManager

Li Lo
  • 15,894