Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
Google "sudo shutdown" and "sudoers" –  Boris Bukh Dec 8 '11 at 14:05

3 Answers 3

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

share|improve this answer

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?.

share|improve this answer
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 8 '11 at 14:39

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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