Linux Crash Course – sudo

When you need to run Linux commands with elevated privileges, sudo is the tried and true method to run commands as another user (such as root). In this introductory tutorial, we’ll take a look at some of the inner-workings of sudo.

YouTube player

Notable Replies

  1. Great video - I finally got around to tinkering with my /etc/sudoers file. :+1:

    To avoid confusion if you get a syntax error, I’ll recommend that you define the following function in your ~/.bashrc (or another file sourced from ~/.bashrc).

    # Improved visudo command
    editsudo () {
      echo "Valid options at the 'What now?' prompt:"
      echo "  e : Re-edit the sudoers file"
      echo "  x : Exit without saving the changes"
      echo "  Q : Quit and save changes (NOT recommended)"
      sudo visudo
    }
    

    Now this has 2 advantages:

    1. The command editsudo ensures to run sudo visudo (so it’s shorter).
    2. The command editsudo prints a help text first, so that if you exits out with an error you have the relevant info right above.
  2. Avatar for bart bart says:

    That’s a really good suggestion!

    I rarely use sudo, unless I’m sure it’s just for one quick command. At least on my system, sudo requires a root password. Some distros don’t have the root account enabled and so sudo uses the user password. To me, it’s just too Windows like (Do you want to allow (xxxx) to make changes to your system?) Well Yes, of course! Just asking for problems. That’s just my opinion. And we all know what opinions are like! :slight_smile:

Continue the discussion at community.learnlinux.tv

Participants