1

On Linux Mint 20+, I don't have to type sudo apt upgrade. I only type apt upgrade, the prompt asks for sudo password and the command is executed with elevated privileges.

How is that achieved?

5
  • 6
    Does type apt return anything enlightening? Commented Aug 2, 2021 at 16:51
  • 2
    it returns /usr/local/bin/apt. If this file there is a line command = ["sudo"] + command and then something like subprocess.Popen(command, stdout=subprocess.PIPE), so to my understanding, apt will launch another program that will be sudo apt-get ? Why isn't this the same on all distros? Commented Aug 3, 2021 at 15:46
  • 3
    Rather than "something like", please add your discovery to your question Commented Aug 3, 2021 at 16:37
  • It this a pure install, or are there site specific changes? /usr/local/… and /opt/… are for site specific changes, not for use by the OS supplier. Commented Aug 31, 2021 at 8:46
  • it's a pure install of linux Mint 20.2 Cinnamon, I never touch anything in it Commented Sep 2, 2021 at 14:51

1 Answer 1

3

You said there's something like this in /usr/local/bin/apt:

command = ["sudo"] + command
subprocess.Popen(command, stdout=subprocess.PIPE)

which looks like a Python script that builds a command line and stacks sudo at the start, to save you the trouble.

It looks like the same script serves some other commands too, there's something about e.g. here.

Now, if you like, you could check what ls -ld /usr/local/bin/apt says, to see if it's a symlink to the actual script or such. The code above and in the linked article looks like it uses the name the script is called under to find which program to actually run.

Why isn't this the same on all distros?

Because the others haven't bothered to provide such a wrapper, possibly because they don't think it's worth it. While it's true that installing packages with apt is somewhat difficult without privileges, it does have other functions too, like apt search, which don't need privileges. In general, it's impossible to list all the programs that would need them. Something like rm might or might not need them depending on the situation.

And then you get the situation where you need to use sudo for some commands, but not for others, and that's confusing. (Probably some might also argue that users should be forced to type sudo every time, so that they stay aware of when they're using raised privileges.)

2
  • 2
    apt is not difficult to use without privileges! I often run apt search and apt show as my ordinary user (I think that requires my user to be a memer of some group, but I don't remember which), before proceeding to install a package (with privileges). Commented Aug 5, 2021 at 13:46
  • @Henriksupportsthecommunity, yep, point, I tend to only use apt-cache search. I guess apt search is similar but different. Commented Aug 5, 2021 at 14:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.