sudo without a password

Posted on November 14, 2010

Note, this is not something I recommend doing. In fact, the only reason why I'm documenting it is that I am removing this solution from the last box I used to have it on.

Anyway, edit the /etc/sudoers file (with visudo, as root), then add lines under the default one for root, like this:

# User privilege specification
root	ALL=(ALL) ALL
bolt    ALL=(ALL) ALL

(replace "bolt" with your own username)

If you would rather want to not type a password only for specific commands, specify them like this:

bolt	ALL=NOPASSWD: /sbin/shutdown, /bin/mount, /bin/umount

(replacing the username and commands with the ones you want)

Filed under: Linux, Reference No Comments

Using Flags and Arguments in Bash

Posted on November 8, 2010

Here's a simple example script, showing how to deal with different inputs depending on the flag preceding them:

USAGE="Usage: Enter a noun after either -p (polite) or -i (insulting)."

while getopts ":p:i:" OPTIONS; do
  case $OPTIONS in
    p ) polite=$OPTARG;;
    i ) insulting=$OPTARG;;
    h ) echo $USAGE;;
    \? ) echo $USAGE
         exit 1;;
    * ) echo $usage
        exit 1;;

if [ $polite ];then echo "Your $polite smells good."; fi
if [ $insulting ];then echo "Your $insulting smells bad."; fi

Stolen fromĀ

Filed under: Linux, Reference No Comments