-2

I want to install sudo so I typed command apt-get update then it shows the following error:

reading packages lists...done
W: chmod 0700 of directory /var/lib/apt/lists/partial failed -
E: could not open lock file /var/lib/apt/lists/lock - open (13:permission denied)
E: unable to lock directory /var/lib/apt/lists/ 
W: problem unlocking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13:permission denied)
W: problem unlocking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13:permission denied)
Kulfy
  • 17,696

1 Answers1

1

I'm assuming you deleted sudo? If the root account has a password set you can login as root user or use su -c "apt-get install sudo"

If the root user has no password which is most likely the case, you can edit the /etc/shadow file by mounting your hard drive with a live cd. The first line will contain the entry for root user, something like this: root:!:17828:0:99999:7::: ! is where the hash of your wanted password should go.

Create a backup of this file, then just copy the hash from your normal user to the root user. It should look something like: $6$bxwJfzor$MUhUWO0MUgdkWfPPEydqgZpm.YtPMI/gaM4lVqhP21LFNWmSJ821kvJnIyoODYtBh.SF9aR7ciQBRCcw5bgjX0 Copy this to the place of the ! sign, save and reboot. You should be able to login to root user using your normal users password. Install sudo and then restore the copy you created to make sure root has no password again. There might be more efficient ways of doing this but this is what came to my mind.

ataalik
  • 81
  • 8