Execute sudo without Password?
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.
command-line password sudo root
add a comment |
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.
command-line password sudo root
2
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
1
For sure you can prolong the timeout. Also, if you're frequently doing fresh server setups you should think about automating the process. You are not paid to type, you are paid to solve problems and to get sh*t done.
– MauganRa
Oct 12 '16 at 18:43
Related: How to run sudo command with no password?
– Eliah Kagan
Jul 26 '17 at 7:12
add a comment |
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.
command-line password sudo root
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.
command-line password sudo root
command-line password sudo root
edited Apr 13 '17 at 12:23
Community♦
1
1
asked Jun 6 '12 at 12:30
Z9iTZ9iT
4,117102640
4,117102640
2
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
1
For sure you can prolong the timeout. Also, if you're frequently doing fresh server setups you should think about automating the process. You are not paid to type, you are paid to solve problems and to get sh*t done.
– MauganRa
Oct 12 '16 at 18:43
Related: How to run sudo command with no password?
– Eliah Kagan
Jul 26 '17 at 7:12
add a comment |
2
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
1
For sure you can prolong the timeout. Also, if you're frequently doing fresh server setups you should think about automating the process. You are not paid to type, you are paid to solve problems and to get sh*t done.
– MauganRa
Oct 12 '16 at 18:43
Related: How to run sudo command with no password?
– Eliah Kagan
Jul 26 '17 at 7:12
2
2
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
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
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
You need to read the discussion in: askubuntu.com/questions/135428/…
– david6
Jun 9 '12 at 1:18
1
1
For sure you can prolong the timeout. Also, if you're frequently doing fresh server setups you should think about automating the process. You are not paid to type, you are paid to solve problems and to get sh*t done.
– MauganRa
Oct 12 '16 at 18:43
For sure you can prolong the timeout. Also, if you're frequently doing fresh server setups you should think about automating the process. You are not paid to type, you are paid to solve problems and to get sh*t done.
– MauganRa
Oct 12 '16 at 18:43
Related: How to run sudo command with no password?
– Eliah Kagan
Jul 26 '17 at 7:12
Related: How to run sudo command with no password?
– Eliah Kagan
Jul 26 '17 at 7:12
add a comment |
9 Answers
9
active
oldest
votes
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.
2
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
1
@Z9iT until you typeexit
or until you close the terminal emulator window.
– Bruno Pereira
Jun 8 '12 at 8:33
2
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
3
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
2
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
|
show 3 more comments
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:
$USER ALL=(ALL) NOPASSWD: ALL
Where $USER
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).
]
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.
I think this is what you want.
11
It's recommended to usesudo visudo
instead of editing it directly. Also changing the permissions of the sudoers may lock yourself out. When editing withvim
, 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
6
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
6
@wil93 you are missing the point: a script that calls forsudo 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
9
@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 dorm -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
4
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
|
show 13 more comments
Root sudo timeouts are the easiest and safest way of doing this. I'll 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
Enter to write the file and :q
Enter 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! Enter.
Hit Ctrl+X, then Y, then Enter 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:
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 <username>
with your username (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 (Ctrl+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.
The 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
However, if you must enable root logins, you can do it like this:
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 the 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
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
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
The EDITOR environment variable can set the editor used... e.g.sudo env EDITOR=/bin/nano visudo
to reliably editsudoers
in nano. (update-alternatives can be used to set the editor as well)
– Gert van den Berg
Nov 19 '18 at 12:10
add a comment |
The preferred way to grant individual (or group) permissions would be to add files under /etc/sudoers.d
This separates local changes from the default policy and saves time in case the distribution sudoers file changes.
For example:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/username
Will make it very clear which users are granted permission.
Similarly, one file can be used to manage multiple directives:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/local
Please see /etc/sudoers.d/README
for more information.
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
1
The right way is to do it withtee
command.
– woto
Jan 19 '18 at 8:10
1
This is a better way that works:sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed bysudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
Insudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.
– Konstantin Pelepelin
Nov 26 '18 at 13:23
the tee method, without permission issues:echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
add a comment |
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)'
2
I think you could just do:echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo env EDITOR="tee -a" visudo
, onlyvisudo
needssudo
after all (and evenenv
won't be needed in the default configuration, IIRC).
– muru
Jun 27 '16 at 20:38
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".
– michael
Sep 20 '16 at 6:47
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
You still need tosudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.
– user2442
Nov 14 '18 at 16:33
add a comment |
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.
11
sudo -s
orsudo -i
are probably both better ideas thansudo bash
, because they ensure the environment is sane and things.
– Darael
Jun 27 '12 at 20:59
2
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
2
a number ofsudo
commands (thinking especially ofsudo pip ...
) requiresudo -H
(set HOME) in order for the command to run properly. In other cases,sudo -E
(preserve env) may be required. Runningsudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.
– michael
Sep 20 '16 at 6:43
1
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
add a comment |
From Super User comes a good answer:
Use the -S switch which reads the password from STDIN:
echo <password> | sudo -S <command>
Replace <password>
with your password.
1
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
@HappyCactus can you place once space in front ofecho
so it doesn't appear in history?
– WinEunuuchs2Unix
Nov 5 '18 at 15:09
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
|
show 1 more comment
This is a one line solution that also changes files permissions as stated in /etc/sudoer.d/README
:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)' & sudo chmod 440 $(logname)
add a comment |
One liner
sudo sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g'
add a comment |
protected by Sergiy Kolodyazhnyy Jan 11 at 8:34
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
2
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
1
@Z9iT until you typeexit
or until you close the terminal emulator window.
– Bruno Pereira
Jun 8 '12 at 8:33
2
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
3
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
2
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
|
show 3 more comments
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.
2
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
1
@Z9iT until you typeexit
or until you close the terminal emulator window.
– Bruno Pereira
Jun 8 '12 at 8:33
2
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
3
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
2
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
|
show 3 more comments
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.
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.
edited Nov 11 '14 at 22:42
answered Jun 6 '12 at 13:36
Bruno PereiraBruno Pereira
60.4k26179209
60.4k26179209
2
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
1
@Z9iT until you typeexit
or until you close the terminal emulator window.
– Bruno Pereira
Jun 8 '12 at 8:33
2
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
3
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
2
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
|
show 3 more comments
2
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
1
@Z9iT until you typeexit
or until you close the terminal emulator window.
– Bruno Pereira
Jun 8 '12 at 8:33
2
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
3
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
2
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
2
2
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
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
1
1
@Z9iT until you type
exit
or until you close the terminal emulator window.– Bruno Pereira
Jun 8 '12 at 8:33
@Z9iT until you type
exit
or until you close the terminal emulator window.– Bruno Pereira
Jun 8 '12 at 8:33
2
2
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
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
3
3
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
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
2
2
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
Not if you're running a virtual machine in a secured environment and you just want the thing to do something immediately and you do not want to deal with passwords. This answer does not answer the question, while it is arguably helpful information. I agree with Adam F
– Jonathan Komar
Aug 10 '16 at 8:34
|
show 3 more comments
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:
$USER ALL=(ALL) NOPASSWD: ALL
Where $USER
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).
]
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.
I think this is what you want.
11
It's recommended to usesudo visudo
instead of editing it directly. Also changing the permissions of the sudoers may lock yourself out. When editing withvim
, 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
6
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
6
@wil93 you are missing the point: a script that calls forsudo 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
9
@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 dorm -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
4
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
|
show 13 more comments
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:
$USER ALL=(ALL) NOPASSWD: ALL
Where $USER
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).
]
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.
I think this is what you want.
11
It's recommended to usesudo visudo
instead of editing it directly. Also changing the permissions of the sudoers may lock yourself out. When editing withvim
, 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
6
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
6
@wil93 you are missing the point: a script that calls forsudo 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
9
@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 dorm -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
4
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
|
show 13 more comments
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:
$USER ALL=(ALL) NOPASSWD: ALL
Where $USER
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).
]
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.
I think this is what you want.
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:
$USER ALL=(ALL) NOPASSWD: ALL
Where $USER
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).
]
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.
I think this is what you want.
edited Aug 3 '18 at 22:17
Community♦
1
1
answered Jun 6 '12 at 13:20
Octávio Filipe GonçalvesOctávio Filipe Gonçalves
11k41423
11k41423
11
It's recommended to usesudo visudo
instead of editing it directly. Also changing the permissions of the sudoers may lock yourself out. When editing withvim
, 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
6
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
6
@wil93 you are missing the point: a script that calls forsudo 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
9
@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 dorm -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
4
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
|
show 13 more comments
11
It's recommended to usesudo visudo
instead of editing it directly. Also changing the permissions of the sudoers may lock yourself out. When editing withvim
, 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
6
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
6
@wil93 you are missing the point: a script that calls forsudo 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
9
@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 dorm -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
4
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
11
11
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
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
6
6
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
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
6
6
@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
@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
9
9
@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
@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
4
4
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
Agree with @wil93. When running a untrusted script, inputing password is no more than a chance to cancel the process, while I doubt it's useless for most people. The point is you know where the script from and what it does.
– Chad
Sep 4 '16 at 8:49
|
show 13 more comments
Root sudo timeouts are the easiest and safest way of doing this. I'll 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
Enter to write the file and :q
Enter 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! Enter.
Hit Ctrl+X, then Y, then Enter 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:
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 <username>
with your username (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 (Ctrl+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.
The 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
However, if you must enable root logins, you can do it like this:
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 the 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
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
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
The EDITOR environment variable can set the editor used... e.g.sudo env EDITOR=/bin/nano visudo
to reliably editsudoers
in nano. (update-alternatives can be used to set the editor as well)
– Gert van den Berg
Nov 19 '18 at 12:10
add a comment |
Root sudo timeouts are the easiest and safest way of doing this. I'll 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
Enter to write the file and :q
Enter 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! Enter.
Hit Ctrl+X, then Y, then Enter 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:
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 <username>
with your username (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 (Ctrl+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.
The 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
However, if you must enable root logins, you can do it like this:
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 the 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
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
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
The EDITOR environment variable can set the editor used... e.g.sudo env EDITOR=/bin/nano visudo
to reliably editsudoers
in nano. (update-alternatives can be used to set the editor as well)
– Gert van den Berg
Nov 19 '18 at 12:10
add a comment |
Root sudo timeouts are the easiest and safest way of doing this. I'll 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
Enter to write the file and :q
Enter 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! Enter.
Hit Ctrl+X, then Y, then Enter 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:
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 <username>
with your username (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 (Ctrl+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.
The 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
However, if you must enable root logins, you can do it like this:
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 the 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
Root sudo timeouts are the easiest and safest way of doing this. I'll 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
Enter to write the file and :q
Enter 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! Enter.
Hit Ctrl+X, then Y, then Enter 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:
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 <username>
with your username (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 (Ctrl+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.
The 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
However, if you must enable root logins, you can do it like this:
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 the 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
edited Jul 30 '17 at 23:56
Eliah Kagan
82.7k22227369
82.7k22227369
answered Oct 30 '13 at 1:15
user209328user209328
35133
35133
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
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
The EDITOR environment variable can set the editor used... e.g.sudo env EDITOR=/bin/nano visudo
to reliably editsudoers
in nano. (update-alternatives can be used to set the editor as well)
– Gert van den Berg
Nov 19 '18 at 12:10
add a comment |
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
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
The EDITOR environment variable can set the editor used... e.g.sudo env EDITOR=/bin/nano visudo
to reliably editsudoers
in nano. (update-alternatives can be used to set the editor as well)
– Gert van den Berg
Nov 19 '18 at 12:10
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
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
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
This was a late answer, but is the most comprehensive in terms of the options it gives you.
– jenming
Mar 4 '17 at 23:12
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
Hmm, on Ubuntu 18.04 MATE this works perfectly, while doing the same on Ubuntu 18.04 GNOME caused me wrinkles with the "username is not in the sudoers file..." problem. Now, this is why so many pple just hate linux - cuz it is rarely "causal" :D Just in case U run into the same... This is how you fix the problem: tecmint.com/…
– Peter
Nov 12 '18 at 20:33
The EDITOR environment variable can set the editor used... e.g.
sudo env EDITOR=/bin/nano visudo
to reliably edit sudoers
in nano. (update-alternatives can be used to set the editor as well)– Gert van den Berg
Nov 19 '18 at 12:10
The EDITOR environment variable can set the editor used... e.g.
sudo env EDITOR=/bin/nano visudo
to reliably edit sudoers
in nano. (update-alternatives can be used to set the editor as well)– Gert van den Berg
Nov 19 '18 at 12:10
add a comment |
The preferred way to grant individual (or group) permissions would be to add files under /etc/sudoers.d
This separates local changes from the default policy and saves time in case the distribution sudoers file changes.
For example:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/username
Will make it very clear which users are granted permission.
Similarly, one file can be used to manage multiple directives:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/local
Please see /etc/sudoers.d/README
for more information.
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
1
The right way is to do it withtee
command.
– woto
Jan 19 '18 at 8:10
1
This is a better way that works:sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed bysudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
Insudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.
– Konstantin Pelepelin
Nov 26 '18 at 13:23
the tee method, without permission issues:echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
add a comment |
The preferred way to grant individual (or group) permissions would be to add files under /etc/sudoers.d
This separates local changes from the default policy and saves time in case the distribution sudoers file changes.
For example:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/username
Will make it very clear which users are granted permission.
Similarly, one file can be used to manage multiple directives:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/local
Please see /etc/sudoers.d/README
for more information.
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
1
The right way is to do it withtee
command.
– woto
Jan 19 '18 at 8:10
1
This is a better way that works:sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed bysudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
Insudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.
– Konstantin Pelepelin
Nov 26 '18 at 13:23
the tee method, without permission issues:echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
add a comment |
The preferred way to grant individual (or group) permissions would be to add files under /etc/sudoers.d
This separates local changes from the default policy and saves time in case the distribution sudoers file changes.
For example:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/username
Will make it very clear which users are granted permission.
Similarly, one file can be used to manage multiple directives:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/local
Please see /etc/sudoers.d/README
for more information.
The preferred way to grant individual (or group) permissions would be to add files under /etc/sudoers.d
This separates local changes from the default policy and saves time in case the distribution sudoers file changes.
For example:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/username
Will make it very clear which users are granted permission.
Similarly, one file can be used to manage multiple directives:
sudo echo "username ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/local
Please see /etc/sudoers.d/README
for more information.
edited Feb 1 '17 at 16:00
muru
1
1
answered Feb 1 '17 at 15:54
user1656671user1656671
33436
33436
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
1
The right way is to do it withtee
command.
– woto
Jan 19 '18 at 8:10
1
This is a better way that works:sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed bysudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
Insudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.
– Konstantin Pelepelin
Nov 26 '18 at 13:23
the tee method, without permission issues:echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
add a comment |
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
1
The right way is to do it withtee
command.
– woto
Jan 19 '18 at 8:10
1
This is a better way that works:sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed bysudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
Insudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.
– Konstantin Pelepelin
Nov 26 '18 at 13:23
the tee method, without permission issues:echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
the echo command failed, even though i'm root. but, I added the file and edited it directly and this worked on latest ubuntu (whereas adding the user to the sudoers directly did not!)
– scape
Oct 24 '17 at 13:43
1
1
The right way is to do it with
tee
command.– woto
Jan 19 '18 at 8:10
The right way is to do it with
tee
command.– woto
Jan 19 '18 at 8:10
1
1
This is a better way that works:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed by sudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
This is a better way that works:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)'
, followed by sudo chmod 440 /etc/sudoers.d/$(logname)
– user2442
Nov 14 '18 at 16:32
In
sudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.– Konstantin Pelepelin
Nov 26 '18 at 13:23
In
sudo ... >file
shell redirection is executed in the original shell, so it could work only in root shell.– Konstantin Pelepelin
Nov 26 '18 at 13:23
the tee method, without permission issues:
echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
the tee method, without permission issues:
echo "username ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/username
– Carson Ip
Nov 27 '18 at 9:42
add a comment |
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)'
2
I think you could just do:echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo env EDITOR="tee -a" visudo
, onlyvisudo
needssudo
after all (and evenenv
won't be needed in the default configuration, IIRC).
– muru
Jun 27 '16 at 20:38
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".
– michael
Sep 20 '16 at 6:47
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
You still need tosudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.
– user2442
Nov 14 '18 at 16:33
add a comment |
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)'
2
I think you could just do:echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo env EDITOR="tee -a" visudo
, onlyvisudo
needssudo
after all (and evenenv
won't be needed in the default configuration, IIRC).
– muru
Jun 27 '16 at 20:38
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".
– michael
Sep 20 '16 at 6:47
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
You still need tosudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.
– user2442
Nov 14 '18 at 16:33
add a comment |
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)'
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)'
answered Jun 27 '16 at 17:50
Eric LandryEric Landry
16113
16113
2
I think you could just do:echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo env EDITOR="tee -a" visudo
, onlyvisudo
needssudo
after all (and evenenv
won't be needed in the default configuration, IIRC).
– muru
Jun 27 '16 at 20:38
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".
– michael
Sep 20 '16 at 6:47
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
You still need tosudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.
– user2442
Nov 14 '18 at 16:33
add a comment |
2
I think you could just do:echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo env EDITOR="tee -a" visudo
, onlyvisudo
needssudo
after all (and evenenv
won't be needed in the default configuration, IIRC).
– muru
Jun 27 '16 at 20:38
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".
– michael
Sep 20 '16 at 6:47
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
You still need tosudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.
– user2442
Nov 14 '18 at 16:33
2
2
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 '16 at 20:38
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 '16 at 20:38
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (
sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".– michael
Sep 20 '16 at 6:47
there's so much that could go wrong here (all user-error, of course), that it is preferred, in my very humble opinion, to edit the sudoer file directly (
sudo visudo
), while testing the result (with the editor still open), for those new users that might be tempted to try this "one-liner".– michael
Sep 20 '16 at 6:47
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
Thanks for the feedback! I was just quickly trying to script-ify the removal of sudo password prompt in my volatile test VMs. Feel free to suggest improvements :)
– Eric Landry
Sep 21 '16 at 16:35
You still need to
sudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.– user2442
Nov 14 '18 at 16:33
You still need to
sudo chmod 440 /etc/sudoers.d/$(logname)
to correct file permissions as stated in the README in that directory.– user2442
Nov 14 '18 at 16:33
add a comment |
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.
11
sudo -s
orsudo -i
are probably both better ideas thansudo bash
, because they ensure the environment is sane and things.
– Darael
Jun 27 '12 at 20:59
2
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
2
a number ofsudo
commands (thinking especially ofsudo pip ...
) requiresudo -H
(set HOME) in order for the command to run properly. In other cases,sudo -E
(preserve env) may be required. Runningsudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.
– michael
Sep 20 '16 at 6:43
1
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
add a comment |
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.
11
sudo -s
orsudo -i
are probably both better ideas thansudo bash
, because they ensure the environment is sane and things.
– Darael
Jun 27 '12 at 20:59
2
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
2
a number ofsudo
commands (thinking especially ofsudo pip ...
) requiresudo -H
(set HOME) in order for the command to run properly. In other cases,sudo -E
(preserve env) may be required. Runningsudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.
– michael
Sep 20 '16 at 6:43
1
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
add a comment |
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.
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.
answered Jun 6 '12 at 13:27
John S GruberJohn S Gruber
11.6k32959
11.6k32959
11
sudo -s
orsudo -i
are probably both better ideas thansudo bash
, because they ensure the environment is sane and things.
– Darael
Jun 27 '12 at 20:59
2
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
2
a number ofsudo
commands (thinking especially ofsudo pip ...
) requiresudo -H
(set HOME) in order for the command to run properly. In other cases,sudo -E
(preserve env) may be required. Runningsudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.
– michael
Sep 20 '16 at 6:43
1
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
add a comment |
11
sudo -s
orsudo -i
are probably both better ideas thansudo bash
, because they ensure the environment is sane and things.
– Darael
Jun 27 '12 at 20:59
2
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
2
a number ofsudo
commands (thinking especially ofsudo pip ...
) requiresudo -H
(set HOME) in order for the command to run properly. In other cases,sudo -E
(preserve env) may be required. Runningsudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.
– michael
Sep 20 '16 at 6:43
1
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
11
11
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
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
2
2
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
"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 askubuntu.com/questions/376199/… )
– Nuzzolilo
Jan 2 '16 at 22:58
2
2
a number of
sudo
commands (thinking especially of sudo pip ...
) require sudo -H
(set HOME) in order for the command to run properly. In other cases, sudo -E
(preserve env) may be required. Running sudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.– michael
Sep 20 '16 at 6:43
a number of
sudo
commands (thinking especially of sudo pip ...
) require sudo -H
(set HOME) in order for the command to run properly. In other cases, sudo -E
(preserve env) may be required. Running sudo bash
probably will work in most cases, but not in all, and when it doesn't, it won't be clear as to why.– michael
Sep 20 '16 at 6:43
1
1
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
sudo su is the traditional way to switch roles and start acting a sys admin.
– user1656671
Jan 21 '18 at 12:49
add a comment |
From Super User comes a good answer:
Use the -S switch which reads the password from STDIN:
echo <password> | sudo -S <command>
Replace <password>
with your password.
1
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
@HappyCactus can you place once space in front ofecho
so it doesn't appear in history?
– WinEunuuchs2Unix
Nov 5 '18 at 15:09
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
|
show 1 more comment
From Super User comes a good answer:
Use the -S switch which reads the password from STDIN:
echo <password> | sudo -S <command>
Replace <password>
with your password.
1
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
@HappyCactus can you place once space in front ofecho
so it doesn't appear in history?
– WinEunuuchs2Unix
Nov 5 '18 at 15:09
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
|
show 1 more comment
From Super User comes a good answer:
Use the -S switch which reads the password from STDIN:
echo <password> | sudo -S <command>
Replace <password>
with your password.
From Super User comes a good answer:
Use the -S switch which reads the password from STDIN:
echo <password> | sudo -S <command>
Replace <password>
with your password.
answered May 17 '18 at 0:12
WinEunuuchs2UnixWinEunuuchs2Unix
46.6k1190182
46.6k1190182
1
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
@HappyCactus can you place once space in front ofecho
so it doesn't appear in history?
– WinEunuuchs2Unix
Nov 5 '18 at 15:09
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
|
show 1 more comment
1
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
@HappyCactus can you place once space in front ofecho
so it doesn't appear in history?
– WinEunuuchs2Unix
Nov 5 '18 at 15:09
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
1
1
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
This is not suggested, because the password remains in cleartype in the shell history file. Apply any of other solutions instead.
– HappyCactus
Nov 5 '18 at 15:02
@HappyCactus can you place once space in front of
echo
so it doesn't appear in history?– WinEunuuchs2Unix
Nov 5 '18 at 15:09
@HappyCactus can you place once space in front of
echo
so it doesn't appear in history?– WinEunuuchs2Unix
Nov 5 '18 at 15:09
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
Yes this will avoid exposing the cleartext password to the history file. But do you always remember to add it ? :-)
– HappyCactus
Nov 5 '18 at 15:38
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
@HappyCactus I tend to add leading space by accident and then get annoyed when history can't be recalled :) Anyway the Super User has 129 upvotes so I think it's a good answer to leave here. People will read our comments and know of the risks and risk aversion steps.
– WinEunuuchs2Unix
Nov 5 '18 at 15:41
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
I Totally Agree. Have a nice day!
– HappyCactus
Nov 5 '18 at 15:43
|
show 1 more comment
This is a one line solution that also changes files permissions as stated in /etc/sudoer.d/README
:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)' & sudo chmod 440 $(logname)
add a comment |
This is a one line solution that also changes files permissions as stated in /etc/sudoer.d/README
:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)' & sudo chmod 440 $(logname)
add a comment |
This is a one line solution that also changes files permissions as stated in /etc/sudoer.d/README
:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)' & sudo chmod 440 $(logname)
This is a one line solution that also changes files permissions as stated in /etc/sudoer.d/README
:
sudo sh -c 'echo "$(logname) ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/$(logname)' & sudo chmod 440 $(logname)
edited Nov 14 '18 at 17:18
answered Nov 14 '18 at 16:39
user2442user2442
1113
1113
add a comment |
add a comment |
One liner
sudo sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g'
add a comment |
One liner
sudo sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g'
add a comment |
One liner
sudo sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g'
One liner
sudo sed -i /etc/sudoers -re 's/^%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g'
answered Feb 17 at 4:21
upteryxupteryx
463
463
add a comment |
add a comment |
protected by Sergiy Kolodyazhnyy Jan 11 at 8:34
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
2
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
1
For sure you can prolong the timeout. Also, if you're frequently doing fresh server setups you should think about automating the process. You are not paid to type, you are paid to solve problems and to get sh*t done.
– MauganRa
Oct 12 '16 at 18:43
Related: How to run sudo command with no password?
– Eliah Kagan
Jul 26 '17 at 7:12