Can sudo be reinstalled after being removed?
Solution 1
I can install applications using:
pkexec apt-get install <appname>
From man pkexec
:
pkexec allows an authorized user to execute PROGRAM as another user. If username is not specified, then the program will be executed as the administrative super user, root.
So, I suppose that pkexec apt-get install sudo
should work as well.
Edit: now I can confirm: yes, sudo
can be installed using using pkexec apt-get install sudo
:
Solution 2
You can always boot into Recovery Mode, drop to root shell and install it without sudo.
Solution 3
Yes, reinstalling sudo
package would be possible via chroot method.
First boot from Ubuntu live disk.
-
Mount the previously installed Ubuntu partition into whatever directory you want.In my case, i mounted it in
/media/ubuntu
.sudo mkdir /media/ubuntu sudo mount /dev/sdaX /media/ubuntu # /dev/sdaX - previously installed Ubuntu partition.
-
By default you didn't able to get internet connection after chrooted into a partition.So run the below command to make it work.
for d in dev sys run proc; do sudo mount --bind /$d /media/ubuntu/$d ; done
Thanks to @Oli for this wonderful piece of code .
-
Now chroot into that mounted directory,
$ sudo chroot /media/ubuntu # apt-get update
-
Install
sudo
package by running,# apt-get install sudo
-
Now exit out of chrooted environment.
exit
Finally boot up your Ubuntu OS.Now test your
sudo
command, it will surely works.
Solution 4
Boot with the extra parameter init=/bin/sh
on the kernel command line. This will put you directly into a root shell, from where you can simply run apt-get install sudo
and then reboot. You may need to run /etc/init.d/networking start
to get a working network connection first. Far simpler than messing around with recovery CDs or live disks, if you ask me.
Solution 5
If you already set or update the root
user account password by this command sudo passwd root
then you don't worry about purging sudo
.Just login into your root
account and then install sudo
,
su
apt-get install sudo
Related videos on Youtube
Registered User
An engineer interested in Linux and Machine Learning.
Updated on September 18, 2022Comments
-
Registered User almost 2 years
This seems to be a chicken-egg problem. The most common task using
sudo
is installing and removing software.sudo apt-get purge <appname>
But
sudo
itself can be removed.sudo apt-get purge sudo # Do not run this command on production computers!
This is where the fun comes
ubuntu@ubuntu:~$ sudo bash: /usr/bin/sudo: No such file or directory
Although it's obvious that no person in his right mind will purge
sudo
(other than me), someone can be fooled to run this command (not directly, in its hex mode, or whatever it's called) or a person could SSH in disguised as tech guru and do the mess.So is there a way of reinstalling sudo?
-
user247696 over 10 yearsgood one I never even knew sudo could purged too! linux is just so damn customisable!
-
Registered User over 10 years@CarlWitthoft Android is a linux derivative, than actually being a linux distro. Also google has made many changes in it(which most linux fans hate). Rooting, which is well known on android smartphone, is nothing but an attempt to gain the powers of real linux on android.
-
Carl Witthoft over 10 years@AdityaPatil No argument - I just wanted to make sure people were aware of the difference but wrote too little.
-
Konrad Höffner over 10 yearsCan't you just login as root?
-
Registered User over 10 years@CarlWitthoft I wasn't argumenting, I just extended your comment a little further.
-
boatcoder over 10 yearsSure, just do
sudo apt-get install sudo
, oops too late :-) -
Erokhane over 10 yearsIf sudo was removed, then why would it be needed to reinstall it if Ubuntu is no longer aware of it?
-
Eliah Kagan almost 5 years
-
-
Premkumar over 10 years@RaduRadeanu This is interesting i am going to try this thanks u ......
-
Radu Rădeanu over 10 years@Premkumar Test it with precaution! The last command from the screen shoot should be probably in your case only:
sudo apt-get install gksu ubuntu-minimal
. But better, check which packages was removed in the same time withsudo
. -
Thebluefish over 10 yearscould I theoretically
sudo apt-get purge pkexec
? -
Registered User over 10 yearscan you add the essential and relevant part from the link here?
-
Radu Rădeanu over 10 years@Thebluefish No. Doesn't exist such a package called
pkexec
. -
Thebluefish over 10 yearsAh good to know. Pretty new to Linux myself, and I didn't want to take the chance :p
-
h3. over 10 years@Thebluefish The package is called
policykit-1
(as of 12.04). It can be removed, but at the expense of removing packages that you'd usually want on a desktop system such asgnome-core
andubuntu-desktop
(on a server, it's more likely not to be required by any necessary package). However, Radu, what determines that your account can usepkexec apt-get …
? Is this something that you configured, or does it happen automatically, and if so, what determines that an account can do this? -
Radu Rădeanu over 10 years@Gilles I don't remember to be made some configurations in this sense in the past. So, I suppose that is happen automatically. If you know what determines that an account can do this, please share; this is outside of my area of expertise.
-
Eliah Kagan over 10 years@Gilles I think members of the
sudo
group can usepkexec
. (My experience is that adding users to this group conferspkexec
abilities and removing them from it removespkexec
abilities; in this way,pkexec
abilities seem to be conferred the same was assudo
abilities in the defaultsudoers
config, which makes sense since being able tosudo
andpkexec
as root are mainly what makes a user an administrator in Ubuntu.) I don't think uninstallingsudo
will remove thesudo
group. But I am not totally sure my suppositions are true under all reasonable circumstances. -
Eliah Kagan over 10 yearsI recommend expanding this to explain what you mean by "copy the existing software."
-
web.learner over 10 yearsNot a very easy way to fix it though.
-
Braiam over 10 years@Seth without op intervention I seriously doubt it could be fixed without writing another answer.
-
orion over 10 yearsWell the proper way of doing that would be chroot, but there are so many less barbaric ways. For instance, logging in as root (the NORMAL way), or, if you somehow don't have root password, just set init=/bin/bash as kernel parameter, and you pass by the entire init system including the login authentication.
-
Luís de Sousa over 10 yearsThis may be useful information, but it doesn't answer the question.
-
Oli over 10 yearsIndeed. This really isn't that relevant to a system where root's password is disabled and sudo is installed by default. And if you look at the other answers, you'll see the last paragraph isn't true either.
-
orion over 10 yearsA user that contemplates removing
sudo
from ubuntu should also consider setting the root password (other questions pointed out how to do that). A user that doesn't care about this stuff, can keep using sudo. -
BЈовић over 10 yearsthis works if the root account is enabled, and on ubuntu it is usually disabled.
su
on my pc gives "su: Authentication failure", although I provided correct password -
Avinash Raj over 10 yearsyes, you are correct that's what i said.If you already updated the root user account password then you don't worry about purging
sudo
.Now try this,sudo passwd root
, it will allows you to update root user account password.Now relogin into your root account by runningsu
command.Once you able to login then you will be free to purge sudo.Now purge sudo bysudo apt-get purge sudo
.Login into your root account to reinstall sudo package by runningsu
andapt-get install sudo
-
Paddy Landau over 10 yearsI understand that
sudo
(with its relativesgksudo
andgksu
, which are not quite the same as each other despite what people will tell you) is being replaced bypkexec
. I have read thatsudo
will not be present in future versions of Ubuntu, though I don't know if that is correct. Whenpkexec
replacessudo
, I don't know what will replacegksudo
. -
Radu Rădeanu over 10 years@PaddyLandau I don't think that
sudo
will not exists in future versions of Ubuntu. Maybe you read aboutgksudo
. See Why is pkexec preferred over gksudo for graphical applications? -
ExploWare over 10 yearsIf there's no recovery available in the grub boot menu, press <kbd>e</kbd> and add ` single` to the bootline. Then, when booted, set a root password using
passwd
. Reboot normaly, on the commandline entersu
followed by the new password, and runapt-get install sudo
(without thesudo
-prefix) -
Avinash Raj over 10 yearsHow did you get internet connection on root shell?
-
Vladimir Ch over 2 yearsi got
bash: pkexec: command not found
lol