sudo is deleted [duplicate]

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.

  1. Boot in recovery mode.
  2. Remount / readwrite by running: mount -o remount,rw /
  3. Ensure pkexec has correct ownership: chown root:root /usr/bin/pkexec
  4. Fix pkexec's permissions: chmod 4755 /usr/bin/pkexec
  5. Boot into your system (exit and follow the prompts), or reboot with reboot.
  6. Follow the above instructions for reinstalling the 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.


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.

  1. Reboot your system.
  2. Long press Shift key or Esc key.
  3. Choose Advanced options for Ubuntu.
  4. Choose Ubuntu, with Linux x.x.x-xx-generic (recovery mode).
  5. Choose root Drop to root shell prompt
  6. Type mount -o rw,remount / command to gain read write access.
  7. Type 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!


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?

  1. Boot from it and mount your PC's system partition.
  2. Copy /usr/bin/sudo from the live system to the mounted partition.
  3. Check that the file's owner and permissions are the same.
  4. Reboot to your system.