9

I've put a command sudo do something in my ~/.bashrc, this works but everytime I open the terminal I have to type in my password. How do I make it so there is no password-typing?

countunique
  • 856
  • 1
  • 10
  • 24

3 Answers3

10

You can use the NOPASSWD attribute in the sudoers file to tell sudo not to require a password. A line like the follows in the sudoers file should let you run that command without a password:

yourlogin ALL=(ALL) NOPASSWD: command_here

To edit the sudoers file, run the command sudo visudo.

carlin.scott
  • 105
  • 3
Dennis Kaarsemaker
  • 6,804
  • 25
  • 38
  • 3
    This operation is too risky. – Hckr Nov 13 '12 at 18:50
  • That depends on the command run. I assume user19192 actually knows what he's doing and wants to run this :) – Dennis Kaarsemaker Nov 13 '12 at 18:51
  • @Hckr I think there's no risk if you have control over **your** script. – Evandro Silva Nov 13 '12 at 18:53
  • Yes, @EvandroSilva . I thought that this operation allows all scripts to be opened as root without password.Cos, I have just seen "command_here".Sorry. – Hckr Nov 13 '12 at 19:03
  • 2
    yeah, `NOPASSWD: ALL` is a different beast. Wouldn't recommend that. – Dennis Kaarsemaker Nov 13 '12 at 19:06
  • 4
    WARNING: Do not use a regular text editor to edit the `sudoers` file, always use the `visudo` command. Because if you mess it up and save it like that, you won't be able to use `sudo` afterwards: http://askubuntu.com/questions/73864/how-to-modify-an-invalid-etc-sudoers-file-it-throws-an-error-and-its-not-allo – Bloke Mar 30 '17 at 08:04
0

You can edit the sudoers file with the command sudo visudo.

As seen here https://unix.stackexchange.com/questions/18830/how-to-run-a-specific-program-as-root-without-a-password-prompt?newreg=fb648518a0b0446e92cb2a685755daca

Your command that you want to authorize should be the path to it or you will get an error.

yourlogin ALL=(ALL) NOPASSWD: /path/to/my/command_here
Allenile
  • 101
  • 1
0

You can edit the sudoers file by executing the following line:

sudo gedit /etc/sudoers

add the following line to the file: your_login ALL=(ALL) NOPASSWD: command

UbuntuHusker
  • 680
  • 6
  • 25
  • NOTE: I generally don't encourage this option because the sudo function is built in to protect the user. no longer requiring a password is negating the purpose of it. However if you are confident it will not be a security problem then go ahead. – UbuntuHusker Nov 13 '12 at 18:51
  • 8
    Using gedit to edit /etc/sudoers is a recipe for disaster. If you make a typo in the sudoers file you can lock yourself out of sudoing. Always use `visudo` to edit: `export EDITOR=gedit; sudo -E visudo` – mogsie Jan 22 '14 at 12:20