Currently, for all my commands that require root access, I have to type them out on a command line.
I would like for the GUI to prompt me to key in my password, when sudo is required, instead of having to type out the commands from command line.
Is there any way to enable this? Previously one version of Ubuntu desktop had this feature out of the box.
This version of Ubuntu (that I am now running) I upgraded from a server installation.
I will add, my user account is already added to sudo group. Thus I can run commands such as sudo gedit
or sudo apt-get
but I'm not able to install software in the Ubuntu Software Center.
Best Answer
TL;DR: Try installing the
policykit-1
andpolicykit-1-gnome
packages.You probably need polkit (a.k.a. PolicyKit).
Most graphical system administration utilities in Ubuntu, including the Software Center, can usually be run without
sudo
or anything quite like it. You just run them the same way you'd run any program.When it comes time to perform a task requiring root privileges, they use polkit to perform the required actions. polkit is a separate mechanism from sudo, for allowing administrators to perform actions as root. It's installed on desktop Ubuntu systems but by default is not part of Ubuntu Server installations.
Thus the normal behavior of the Software Center is that you can invoke it simply as
software-center
, it will not prompt you to authenticate at that time, but then when you tell it to install or remove software, it will prompt you (graphically) to authenticate.It sounds from your description like your system started as an Ubuntu Server system with no GUI, and then you installed a GUI. Probably the policykit-1 and policykit-1-gnome packages have not been installed. If you install the, polkit will most likely start working for Software Center and other such utilities.
Then you should be able to just run:
(Or select the Software Center graphically as provided for by whatever desktop environment you installed.)
If you want a fully functional Ubuntu desktop system, I recommend installing the metapackage for whatever "flavor" of Ubuntu you want to turn your system into. Basically, if you want a regular Ubuntu desktop system, install ubuntu-desktop .
This should fill in the various gaps, like not having polkit, that come with installing a more minimal GUI on your server system. On the other hand, if you prefer a more minimal GUI, you can just install those polkit packages.
For more information, see How do you run Ubuntu Server with a GUI?
sudo
with graphical authentication.If you really do need run commands as root but get a graphical authentication dialog, what you're looking for is
gksudo
(orgksu
). This is provided by the gksu package. It is a graphical frontend forsudo
.Typically
gksudo
is used to run graphical applications as root (or some other user besides the user launching them). But you can also use it to run non-graphical commands--provided the commands can be run withsudo
.You can run
gksudo
from a terminal but you don't have to. You can run it from the Alt+F2 (run command) dialog or put it in theExec=
line of a.desktop
file (or any of the other ways you run graphical programs).Note that you should consider using
gksudo
to run graphical applications as root even when you are running them from a terminal, because commands likesudo ...
where...
is a graphical application can actually break the per-application configurations of the non-root users running them. (Fortunately this is fixable.)sudo gedit
is particularly notorious.For more information on the problem with
sudo
for graphical applications and what to do instead, see:man sudo
for the-H
and-i
options.sudo -H ...
andsudo -i ...
do not authenticate graphically, but likegksudo ...
they don't have the problems of plainsudo ...
.There's also polkit-based graphical way ...for non-graphical commands.
gksudo
works fine for running both graphical and non-graphical programs. You should probably use that.But an alternative, using polkit instead of
sudo
and only working for non-graphical programs, ispkexec
.For example, if you run
pkexec touch /root/foo.txt
, you'll be prompted with a graphical authentication dialog, and if the authentication succeeds,touch /root/foo.txt
is run, creating (or freshening)foo.txt
in the/root
folder.pkexec
will use a non-graphical dialog, requiring a terminal, in the event that it cannot create a graphical dialog. But this is unlikely to happen if you're running it through a facility provided by your graphical shell or desktop environment.pkexec
work only for non-graphical programs? Actually it also runs graphical programs, but only if polkit has been specially configured to allow it--which is not usually done. Seeman pkexec
(and the upstream version, with screenshots), this answer and that answer for some details, if you're interested.sudo
vs. polkit (some technical details, only if you're interested)A new
gksu
/gksudo
will use polkit instead ofsudo
to do its work, though this version has not been widely adopted. I mainly bring it up to recommend theREADME
file in its source code (written by Gustavo Noronha Silva), which explains the important differences betweensudo
and polkit. To quote from it briefly:These issues underlie the situation I believe you're in:
gksu
/gksudo
.(...Which may eventually use polkit behind the scenes--but the
gksudo
currently in Ubuntu is the traditional one that usessudo
).