Sitemap

Root Account and sudo

2 min readOct 30, 2024

--

Ever had the problem where you run a command with sudo, and it says 'command not found'? I ran into this recently while setting up k3s as a user, which led me on a tangent to figure out what I could do about it.

Turns out I learned a lot about the root account and sudo. Along with this specific use case, I'll also discuss some general information I didn’t know concretely at the time (or at least didn’t remember since studying it at university).

Get Dave Watts’s stories in your inbox

Join Medium for free to get updates from this writer.

First, I had to download and store k3s in /usr/local/bin for use. Note that when running it as above, it does not preserve the user environment Eg.

This is because sudo inherits only a minimal subset of the user's environment, and a sudo session differs from a root login. This is actually set up in visudo, where you can find these configurations.

Found in visudo

This provides better security by default, so it’s good to know and probably best left as is. What else can we do to control which environment variables get inherited??

Controlling sudo Environment Variables

You can control how sudo handles environment variables:

  • sudo -i: This simulates a full login shell for the root user, inheriting root's environment as if you had logged in as root directly.

Wow — I didn’t know that! I’ve been caught out by this a few times and didn’t realize -i would do this.

--

--