How can I install the sudo package?
$ apt-get install sudo
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
How can I install the sudo package?
$ apt-get install sudo
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
If you've actually deleted the sudo command, you can reinstall the package that provides it by running:
pkexec apt-get update
pkexec apt-get --reinstall install sudo
This works because most Ubuntu systems have two separate ways that let administrators perform actions as root, sudo and Polkit. When sudo is broken, Polkit is usually still intact.
You must be logged in as an administrator to do this, of course. If you're using an account who was allowed to use sudo (back when sudo existed on the system), that should work fine.
On a minimal system or Ubuntu server system, Polkit may be unavailable, and with some configurations you will not be able to run the pkexec command over an SSH session.
You have indicated that pkexec, while not deleted like sudo, is also broken. Specifically, on your system it has the wrong ownership or permissions. It is supposed to be setuid root, but it is not, and therefore it cannot be used.
It would be useful to know how /usr/bin/sudo was deleted, and how /usr/bin/pkexec's permissions (or ownership) got changed. These are two, seemingly separate breaking changes to your system. If a recursive (-R) chown or chmod has been performed on /, /usr, or /usr/bin, that would explain how pkexec's permissions were changed, and an appropriate fix would do more than just changing them back for that one executable.
With that said, if the only two things wrong with your system are that sudo is missing and pkexec has wrong permissions or ownership, this is still easily fixed, though you will have to reboot into recovery mode or chroot in from a live environment. I suggest recovery mode.
/ readwrite by running: mount -o remount,rw /pkexec has correct ownership: chown root:root /usr/bin/pkexecpkexec's permissions: chmod 4755 /usr/bin/pkexecexit and follow the prompts), or reboot with reboot.sudo package by running apt-get with pkexec.This has the advantage of working whether or not any Internet connection is available in recovery mode, without involving downloading .deb files and manually installing them. With --reinstall, apt-get will replace all the package files for sudo, which can fix additional problems. Plus, this also fixes your broken pkexec.
However, this is not the only approach. In particular, the method given in San Lin Naing's answer should work, too. The main difference is that, in the method given here, no package management operations are carried out in the chroot, which is only used to repair pkexec so it can then be used to manage packages when booted normally.
yes i acidentlly deleted the sudo file. the output of ls -l /usr/bin/sudo is cannot access '/usr/bin/sudo': No such file or directory
Just a thought:
You still have the media (DVD / USB stick) from which you installed Ubuntu to your system?
/usr/bin/sudo from the live system to the mounted partition.You need root permission to install any software. But, you had deleted the sudo package.
If you have access as a root, you may be able to install sudo again.
Reference to this answer.
Try to start with bash mode with root user.
Shift key or Esc key.Advanced options for Ubuntu.Ubuntu, with Linux x.x.x-xx-generic (recovery mode).root Drop to root shell promptmount -o rw,remount / command to gain read write access.apt install sudo. Follow on screen instructions.If installation finished, It is done!
If not, this may need network connection.
Lets reboot your system to normal boot and download required files.
If so, Ctrl + D will go menu page again and choose resume. This will go to normal boot.
You may need to install sudo offline. This may be another research. Here you can find .deb package. You can download with your OS version. Download your file that is sudo_1.8.19-3_xxxx.deb. And then remember your download file path.
Reboot your system in bash mode (recovery mode) again and follow 1-6 steps.
And then dpkg -i *file_path/sudo_1.8.19-3_xxxx.deb. This will install sudo. Finished! Ctrl + D and choose resume to normal boot.
Done!
You can build sudo from source
mkdir sudo-src
cd sudo-src
apt-get source sudo
cd sudo-x.y.z
./configure --prefix=$HOME
make
make install