7

How do you input sudo password automaticly when prompted? I can do this in a script by typing: echo PASSWORD | sudo -S Command, but how do I do that always when prompted?

5
  • 1
    Have you read ubuntuforums.org/showthread.php?t=1510272 ?
    – Cornelius
    Apr 21, 2014 at 19:03
  • Do the same: echo PASSWORD | sudo -S Command. What's the problem? Apr 21, 2014 at 19:11
  • But always, even not in a script, like when i click on somthing like the update manager, i would not like to insert the paswd, so what to do?, a week a go i say a video on youtube, a guy had done this but i can't remeber what the video was called, so how do you do it?
    – Alexander
    Apr 21, 2014 at 19:14
  • Found a way, Add "echo Password | sudo -S pwd" to the file /home/username/.bashrc att the end of the line, you will now never have to input your password in terminal again
    – Alexander
    Apr 21, 2014 at 19:18
  • 1
    Just configure sudo to not require a password, see help.ubuntu.com/community/RootSudo
    – Panther
    Apr 21, 2014 at 20:14

1 Answer 1

6

You can modify the sudoers file (using visudo) and use the "NOPASSWD" option to not prompt for a password. From, here page; e.g. man sudoers and searching for NOPASSWD -

NOPASSWD and PASSWD

By default, sudo requires that a user authenticate him or herself before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for the commands that follow it in the Cmnd_Spec_List. Conversely, the PASSWD tag can be used to reverse things. For example:

ray     rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm as root on the machine rushmore without authenticating himself. If we only want ray to be able to run /bin/kill without a password the entry would be:

ray     rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm

Note, however, that the PASSWD tag has no effect on users who are in the group specified by the exempt_group option.

By default, if the NOPASSWD tag is applied to any of the entries for a user on the current host, he or she will be able to run ''sudo -l'' without a password. Additionally, a user may only run ''sudo -v'' without a password if the NOPASSWD tag is present for all a user's entries that pertain to the current host. This behavior may be overridden via the verifypw and listpw options.

2
  • 4
    you shold, IMO , ALWAYS edit with visudo , visudo checks syntax
    – Panther
    Apr 21, 2014 at 20:15
  • @bodhi.zazen Edited. That's great advice. Apr 21, 2014 at 20:16

Not the answer you're looking for? Browse other questions tagged .