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?
I can install applications using:
From
man pkexec
:So, I suppose that
pkexec apt-get install sudo
should work as well.Edit: now I can confirm: yes,
sudo
can be installed using usingpkexec apt-get install sudo
:(click to enlarge)
You can always boot into Recovery Mode, drop to root shell and install it without sudo.
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
.By default you didn't able to get internet connection after chrooted into a partition.So run the below command to make it work.
Thanks to @Oli for this wonderful piece of code .
Now chroot into that mounted directory,
Install
sudo
package by running,Now exit out of chrooted environment.
Finally boot up your Ubuntu OS.Now test your
sudo
command, it will surely works.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 runapt-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.If you already set or update the
root
user account password by this commandsudo passwd root
then you don't worry about purgingsudo
.Just login into yourroot
account and then installsudo
,Click here to enlarge
sudo (and any other root privilege) only applies to the running OS. If you have been silly and removed sudo (or /usr/ for that matter) and don't have alternates like pkexec you can simply boot from something else, copy the missing software, and restart again.
Physical access nullifies any and all software security your system may have.
This problem seems to be very ubuntu-specific. As non-ubuntu user I didn't even understand at first why sudo would be a special case in any way (a lot of distributions don't install it by default).
You don't need sudo at all. It's just a lazy shortcut that allows you to execute a root command without actually logging in as root. However, if you have to do anything more than a single command, it's just awful constantly prefixing everything with sudo. Not to mention that using
sudo
makes users ignorant about how permissions and root account work. It makes much more sense to just login as root, do the administration of the system and logout. That you do withsu
if you are already logged in as a regular user. Or you could log in directly as root.Of course you need to have
root
password set, that's the reasonable configuration, otherwise you have a windows-like system where there are actions that nobody can perform and you are really locked out if somehowsudo
isn't available (it requires working/etc/
, set$PATH
and other things mounted - which you may not have if something goes wrong early in boot).