How-To: Passwordless Sudo

This one is as much for you as it is for me. Every time I install a new system, I forget how to set the /etc/sudoers file so that I can execute certain applications as root using sudo without having to enter my password. This is very useful for scripts, or for harmless commands that you need te execute a lot — like vpnc — but still require root permissions.

Start by opening the editor of the sudoers-file:

$> sudo visudo

This will open the file in vim, which you might not be familiar with. No problem, just type i which puts it in insert-mode and it’ll work as any other editor.

Append a line in the following format at the end:

username ALL=NOPASSWD:command1, command2, ...

For example, mine:

david ALL=NOPASSWD:/usr/sbin/vpnc, /usr/sbin/vpnc-disconnect

As you can see, you need to use the full path for every binary. If you don’t know them by heart, find out using the whereis command:

$> whereis -b vpnc
vpnc: /usr/sbin/vpnc /etc/vpnc.conf /etc/vpnc /usr/share/vpnc

Usually the first result is the correct one.

Save the sudoers file by pressing ESC and typing :wq return. Now you can use sudo on the commands you entered without having to type your password. Have fun!

PS: There’s also a way to allow passwordless sudo for all commands, but I’m not telling how since that really isn’t safe. You’ve run away from Windows for a reason, remember? This is one of them ;) .

This entry was posted in How To, Linux. Bookmark the permalink.

5 Responses to How-To: Passwordless Sudo

  1. sander says:

    Hm, is inderdaad handig voor dingen zoals vpnc. Thanks laddy!

    PS: baeki en dabra op die foto in je zijbalk, geestig.

  2. David says:

    Blij dat’k kon helpen :)

    Die passeren af en toe wel eens ja, om ons extra te ambeteren. Niemand weet vanwaar ze komen… Ok, ja, ik toch niet.

  3. sander says:

    Het zijn rare wezens. Vooral omdat de ene nooit les heeft op de Sterre ^^

  4. Merci voor de tip. Die vpnc werkt al een tijd op mijn zenuwen. (Zeker met een onstabiele home-connectie.) Nu moet ik niet meer telkens mijn password ingeven.

  5. David says:

    Blijkbaar hebben nog veel UGent-ers hier nood aan :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">