Saturday, February 13, 2010

How to make Ubuntu to not ask for password when you do sudo?

There are some commands in ubuntu that do not work without 'sudo'ing. Like while creating a text file you use 'sudo vi' instead of just 'vi' and then you had to enter password again. This is the security scheme used by Ubuntu to save your files from external attacks.

If entering password for every command is uninteresting and frustrating, then here is a solution to it.

Step1 -

Open your terminal and type the following -

sudo visudo

Now enter your password and visudo will appear. Visudo is an editor used to safely edit this file called - sudoers. sudoers is a file located in /etc directory and it contains the information of who can use sudo.



Step2 -

At the end of the file add the following line

%username ALL=(ALL) NOPASSWD: ALL

Make sure you replace username with the username of your account and don't forget to retain the '%' symbol at the beginning. Save & Exit.

That's it. You're done. Though this makes everything easy, it is not so recommended. By enabling this, you will be exposed to attacks since no password is required. There is an alternate way. You can specify all the commands in the statement itself so that only those commands do not need passwords. An example is here -

%username ALL=(ALL) NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

With this, you ll be able to use only kill, ls and lprm commands without password.

No comments:

Post a Comment