1

I'm messing with a Raspbery Pi logged into the pi user, and here's what's happening: When I run something with sudo, I see -bash: sudo: command not found. When I run apt-get install sudo, I see

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?

This would make me think that the pi user simply doesn't have enough permission to use sudo or install it. But, when I run groups pi, I see

pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio

Note the sudo in that list. That means that pi should have permissions to use sudo. So what's the deal? In other words, is the permission to use sudo enough permission to install sudo and then use it?

6
  • sudo, if installed, will permit user pi to sudo su - and such. If sudo package is not installed, the membership of group sudo is somewhat pointless at that stage.
    – steve
    Feb 4, 2021 at 20:06
  • 1
    Which pi distro are you using? What additional config have you done?
    – cryptarch
    Feb 4, 2021 at 20:17
  • @steve why do you ever need to use sudo and su together. They are alternate solutions to the same problem (sudo is newer, more powerful, more adaptable). Just use -s option. But don't. Don't use a root shell (except in a docker container, as they reset when shutdown). Feb 4, 2021 at 20:27
  • @steve you don't need to sudo su. That's saying "Hello sudo, please can I have root... thankyou. Now hello su, although I'm already root please can I have root... Ok thankyou". There's very little point in it, and you can use sudo -s (and in some cases even just sudo) Feb 4, 2021 at 20:38
  • Theo, "Note the sudo in that list. That means that pi should have permissions to use sudo.". Not really, no. That is just a list of groups for your user account. When you have the sudo command installed, its default settings allow members of the sudo group certain access that wouldn't otherwise be permitted. But membership of the sudo group is nothing special in itself. Feb 4, 2021 at 20:42

1 Answer 1

1

The message -bash: sudo: command not found is bash telling you that the command sudo is not found. As you correctly identified, and tried to install it. But you can't install it because you don't have permission, because you can't use sudo.

So where is sudo. I think it is installed by default, but may depend on the OS that you are running (you did not say), and other things (did you remove it, did you do some custom install). It could also be that sudo is installed but not in your PATH. Try /usr/bin/sudo (if that works then your PATH variable is broken).

2
  • in case sudo is not installed, how to install (su)
    – alecxs
    Feb 5, 2021 at 0:12
  • 1
    If you know the root password then you can use su, else you can remove the SD card fix the problem on another machine: The easiest fix that I can think of is to add a root password. Feb 5, 2021 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .