Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 something.sh file to the terminal.

share|improve this question
1  
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: askubuntu.com/questions/135428/… –  david6 Jun 9 '12 at 1:18

4 Answers 4

up vote 16 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
1  
@Z9iT until you type exit or until you close the terminal emulator window. –  Bruno Pereira Jun 8 '12 at 8:33
    
Thanks.. Accepted this answer because it servers the purpose of issuing sudo commands without password authentication for n-hours till the time we won't exit.. Not modifying system files is a plus. –  Z9iT Jun 8 '12 at 9:58

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:

username ALL=(ALL) NOPASSWD: ALL

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).

enter image description here

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.

enter image description here

I think this is what you want.

share|improve this answer
4  
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
    
Thanks for your response. What workout you suggest for the statement by @Lekensteyn –  Z9iT Jun 7 '12 at 21:06
1  
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
    
@BrunoPereira if someone takes control of a user account then he knows the password anyway (or he doesn't know it but he has physical access to the machine, so...) –  wil93 Aug 22 at 1:21
1  
@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 at 12:46

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

,timestamp_timeout=X

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

Example:

michael ALL=NOPASSWD: ALL

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

SYSTEM WIDE GROUP SUDO

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
4  
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

Your Answer

 
discard

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.