Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Inspired by this question....

I am the sole person using my system with 12.04.
Every time I issue a sudo command; the system asks for the user password (which is good in its own way).
However I was thinking; without activating the root account; how can I execute the sudo commands which will not ask for user password to authenticate.

NOTE: I want to execute sudo command without authenticating via password; only when they are executed via terminal.
I don't want to remove this extra layer of security from other functions such a while using 'Ubuntu software center' or executing a bash script by drag-drop file to the terminal.

share|improve this question
so you only want to be asked for the password in the terminal and for other things not, or the other way arround?! in both ways, I think its a high security breach – Dr_Bunsen Jun 6 '12 at 12:33
I want that system may not ask password only when in the terminal... for any other purpose the system must ask a password. This requirement is only temporary, and to be used while configuring n installing new servers.. during fresh server installations, it really take hours of configuring with sudo commands.. issuing password every 15 min. is headache. I don't want to use root account. – Z9iT Jun 6 '12 at 12:44
You need to read the discussion in:… – david6 Jun 9 '12 at 1:18
up vote 29 down vote accepted

sudo -i is the way to go if you don't want to be typing a password every 10 mins while doing modifications in your system (or other systems), and you don't want to modify any system files.

It will switch you to root using your sudo user password, when you close the console or type exit you are back to your normal user.

share|improve this answer
Will this hold true that I enter password only once... and till the time I don't exit; weather 5 hrs. or 15.... the system wont ask for authentication by password when any sudo command is issued. – Z9iT Jun 7 '12 at 21:10
How is it different form activating and using the root account ???? – Z9iT Jun 7 '12 at 21:12
@Z9iT Because you don't actually activate anything or change the root´s user password, there is no system modification at all except you login to a root shell allowing you to do stuff without typing sudo foo all the time. If thats all you want (to be able to type commands without using sudo all the time) and you want 0 modifications to your system this is the way to go imho. – Bruno Pereira Jun 8 '12 at 8:29
@Z9iT until you type exit or until you close the terminal emulator window. – Bruno Pereira Jun 8 '12 at 8:33
This doesn't really answer the question, because you still need to enter the password to become root at that point. – Adam F Jun 2 '15 at 22:00

The approach to solve your problem is to put your user in sudoers file, like you can see.

Open terminal window and type:

sudo visudo

In the bottom of the file, type the follow:


Where username is your username in your system. Save and close sudoers file (if you haven't changed your default terminal editor (you'll know if you have), press ctl+x to exit nano (but note that the screenshot below shows vim), and it'll prompt you to save).

sudoers file]

After this, you can, in terminal window, type sudo <Whatever you want>, without being prompted for the password.

This only applies, to sudo command in terminal window. For example, when you try to install a package in software center, you will be prompted to insert your password, like you can see in the next Screenshot.

gui password prompt

I think this is what you want.

share|improve this answer
It's recommended to use sudo visudo instead of editing it directly. Also changing the permissions of the sudoers may lock yourself out. When editing with vim, use :wq! to write to read-only files and quit the editor. In that way, permissions 644 are not necessary. – Lekensteyn Jun 6 '12 at 13:49
This is a serious security risk, anyone taking over any account with sudo rights can take control of the complete system and lock any further access to this computer, seriously not recommended. – Bruno Pereira Sep 12 '13 at 9:06
@wil93 you are missing the point: a script that calls for sudo install crapware will not ask for a password in this case and might mess up everything you have, and you do not need to be physically next to a machine to distribute scripts last time I checked... This is just an example. – Bruno Pereira Aug 28 '14 at 12:46
@BrunoPereira If you plan on running untrusted scripts then that is the security risk (even if sudo asks for a password, a malicious script could always do rm -rf ~ messing quite some things up). Overall, I wouldn't call «serious security risk» the simple removal of password prompt from sudo. – wil93 Aug 29 '14 at 0:54
@wil93 Define "untrusted"... Do you read every single script you download before running it? No, that would be a hassle. Besides, I said that was just a case in many. – Bruno Pereira Aug 29 '14 at 10:54

Root sudo timeouts are the easiest and safest way of doing this, ill lay out all examples but be warned it is very risky any way you do this although this way is much safer

sudo visudo

This opens an editor and points it to the sudoers file -- Ubuntu defaults to nano, other systems use Vi. You're now a super user editing one of the most important files on your system. No stress!

(Vi specific instructions noted with (vi!). (Ignore these if you're using nano)

Use the arrow keys to move to the end of the Defaults line.

(vi!) press the A (capital "a") key to move at the end of the current line and enter editing mode (append after the last character on the line).

Now type


where X is the timeout expiration in minutes. If you specify 0 you will always be asked the password. If you specify a negative value, the timeout will never expire. E.g. Defaults env_reset,timestamp_timeout=5 (vi!) hit Escape to return to command mode. Now, if you're happy with your editing, type in :w to write the file and :q to exit vi. If you made a mistake, perhaps the easiest way is to redo from start, to exit without saving (hit Escape to enter the command mode) and then type :q! .

Hit CTRL + X, then Y, then to save your file and exit nano.

You might want to read the sudoers and vi manual pages for additional information.

man sudoers

man vi

Reset timeout value using the below

sudo -k

These instructions are to remove the prompt for a password when using the sudo command. The sudo command will still need to be used for Root access though.

Edit the sudoers file

Open a Terminal window. Type in sudo visudo. Add the following line to the END of the file (if not at the end it can be nullified by later entries):

<username> ALL=NOPASSWD: ALL

Replace with your user name (without the <>). This is assuming that Ubuntu has created a group with the same name as your user name, which is typical. You can alternately use the group users or any other such group you are in. Just make sure you are in that group. This can be checked by going to System->Administration->Users and Groups



Type in ^x to exit. This should prompt for an option to save the file, type in Y to save.

Log out, and then log back in. This should now allow you to run the sudo command without being prompted for a password.

root account

Enabling the root account

Enabling the Root account is rarely necessary. Almost everything you need to do as administrator of an Ubuntu system can be done via sudo or gksudo. If you really need a persistent Root login, the best alternative is to simulate a Root login shell using the following command...

sudo -i

sudo passwd root

Re-disabling your root account

If for some reason you have enabled your root account and wish to disable it again, use the following command in terminal...

sudo passwd -dl root


root$ echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

Log out, and then back in.

Reset sudo timeout

You can make sure sudo asks for password next time by running:

sudo -k
share|improve this answer
I posted this before I added, for a system wide way of doing this and others read here: – user209328 Oct 30 '13 at 1:17

Of course what you want to do isn't recommended. After a while, though entering sudo becomes so automatic that its usefulness diminishes.

Another approach is to leave your sudoers file as is and, while doing something complicated to your umpteen hundred servers, enter sudo bash . That will give you a shell that will be authenticated as root until you exit it.

share|improve this answer
sudo -s or sudo -i are probably both better ideas than sudo bash, because they ensure the environment is sane and things. – Darael Jun 27 '12 at 20:59
"sane and things" isn't generally in the realm of "better ideas", could someone give a technical explanation of why sudo -s or sudo -i is better than sudo bash? (Edit: Here is a relevant question… ) – Nuzzolilo Jan 2 at 22:58

Nice one-liner to remove sudo prompts for the current user

sudo bash -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)'
share|improve this answer
I think you could just do: echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo env EDITOR="tee -a" visudo, only visudo needs sudo after all (and even env won't be needed in the default configuration, IIRC). – muru Jun 27 at 20:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.