← Back to list

Root Account and sudo

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…

Dave Watts · 2024-10-30 22:38 · 2 claps · 1.4 min read
#sudo #visudo #system-administration #sysadmin #root-access
Open on Medium ↗
Wiki topics: 🥊 · Combat Sports

Root Account and sudo

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).

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

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.


메타데이터
post_id
5eefef64083a
slug
root-account-and-sudo-5eefef64083a
url
https://medium.com/@wattsdave/root-account-and-sudo-5eefef64083a
canonical_url
https://medium.com/@wattsdave/root-account-and-sudo-5eefef64083a
author_url
https://medium.com/@wattsdave
status
ok
fetched_at
2026-07-22 08:55:38