I have desktop edition of Ubuntu.
I like the Terminal so that that I prefer to shutdown my computer with the shutdown
command.
However when I type shutdown now
it prompts me to enter my password.Is there any way I can shutdown my computer using this command without entering my password?
Open up a terminal (CTRL + T) and type the following
sudo visudo
Add the following line:
or
This allows the user/group to run the above three commands, using sudo, however with no password.
So,
sudo poweroff
will now result in a passwordless shutdown.However, to make this even cleaner, we'll add an alias, so that running
shutdown
callssudo shutdown now
.Open
~/.bash_aliases
for editing.Insert the following line at the end of the file:
Finally, load the changes to the
.bash_aliases
file...Try it out!
Thanks, Eric.
A safe way to do this without using sudo and without tinkering with the system, is by executing these one-liner commands:
For Ubuntu 15.04 and later:
(This is due to Ubuntu's shift in using
systemd
instead ofUpstart
)Since hibernate is normally disabled by default in Ubuntu systems, you can enable this by checking this answer. Original source here.
For Ubuntu 14.10 or earlier:
Shutdown:
Restart:
consolekit should of course be installed your system.
Other commands you may like:
Suspend:
Hibernate: (if enabled on your system)
unity uses many gnome services, and in that case too - you can shutdown gnome way.
will do the job.
While you can use the method of allowing
NOPASSWD
on/usr/sbin/shutdown
, although another, DE-independent solution is to just useinit 0
.On Ubuntu 20.04 LTS, I created a
polkit
file withWith this,
systemctl halt
andsystemctl suspend
work without a password. This also work remotely with e.g.ssh 192.168.0.55 -t 'systemctl suspend'
.that is easy. using -S option like this: