0

Let's say I wanted an automated script to start right after a login prompt. The script, however, needs a user password before it can be executed manually using sudo 'script' command from the terminal.

Now, I suppose I could write a script with the needed password and just set it up as one of the startup apps but the thing is I'm trying to avoid putting any sensitive information inside it. And for now, I want this to be an isolated case.

I'm certain there are workarounds but I'm new to Ubuntu, so any help will be most appreciated.

EDIT: I have tried that. I created a new file in /etc/sudoers.d/ and set the overrides there.

The following line seems to be working just fine:

user ALL = NOPASSWD : ALL

Problem appears when I try setting it up for a specific script:

user ALL = NOPASSWD : /home/user/script

Also tried:

user host = (root) NOPASSWD : /home/user/script

as well as some of the other combinations but nothing works. I'm using Ubuntu 16.04 LTS.

Inside the script there is a simple sudo command and if I run bash 'script', it always asks me for a user password except in the first example but that's exactly what I'm trying to avoid. I only want override for this script.

I have also changed permissions on the sudoers.d/override file as directed in this post.

So I have no idea why it won't work...

  • You first say you want to execute sudo script. Then you say the script executes some sudo command and you run bash script. Make up your mind. If you put user host = (root) NOPASSWD : /home/user/script in sudoers, then you can do sudo /home/user/script without needing a password, no more, no less. – muru Dec 22 '16 at 17:02
  • You have a syntax error: the relevant part is (from the linked post) NOPASSWD: not NOPASSWD : (mind the blank!) – guntbert Dec 22 '16 at 19:11
  • @muru well I haven't been clear enough for which I apologise. It's a script with the line – user633551 Dec 22 '16 at 19:44
  • with the line that executes another script. – user633551 Dec 22 '16 at 19:46
  • @guntbert I tried NOPASSWD: without spacing. Same result. – user633551 Dec 22 '16 at 19:48
  • @muru you were right. Problem was that when the terminal opens you are already in /home/user/ so I assumed the path is already set for the command. – user633551 Dec 22 '16 at 21:53

0 Answers0