You are not logged in.

#1 2020-09-17 01:57:10

TheMohawkNinja
Member
Registered: 2017-07-11
Posts: 47

[SOLVED] Run command in sudo without being prompted for a password.

Hello,

I am trying to setup my sudoers file so I can run some programs that require root access, without needing to be prompted for password (mainly so I can have them start on login). From the research I've done, it seems like my below sudoers file should suffice, however "sudo mount -a" still requires a password to be entered.

I'm guessing it has something to do with the "terminus ALL=(ALL)..." line somehow superseding the "terminus ALL = NOPASSWD:..." line even though it occurs before, but I am not sure how supersedence works in the sudoers file.

(I've removed all the commented bits for brevity, since that's like 95% of the file)

root ALL=(ALL) ALL
Defaults targetpw  # Ask for the password of the target user
terminus ALL=(ALL) ALL  # WARNING: only use this together with 'Defaults targetpw'

#includedir /etc/sudoers.d

terminus ALL = NOPASSWD: /usr/bin/mount

Thank you!

Last edited by TheMohawkNinja (2020-09-17 22:53:11)

Offline

#2 2020-09-17 02:12:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,517
Website

Re: [SOLVED] Run command in sudo without being prompted for a password.

TheMohawkNinja wrote:

mainly so I can have them start on login

Then this is the wrong approach.  Use a systemd service.  For the case of `mount -a` that is included in the system services already - why do you need to do this again?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2020-09-17 02:13:28

solskog
Member
Registered: 2020-09-05
Posts: 462

Re: [SOLVED] Run command in sudo without being prompted for a password.

With the same /etc/sudoers file, I can 'sudo mount -a' with a unprivileged user without pass. I think your sudoers file is correct. Do you have any NFS mount on your /etc/fstab ?

Last edited by solskog (2020-09-17 02:13:59)

Offline

#4 2020-09-17 22:52:40

TheMohawkNinja
Member
Registered: 2017-07-11
Posts: 47

Re: [SOLVED] Run command in sudo without being prompted for a password.

Trilby wrote:
TheMohawkNinja wrote:

mainly so I can have them start on login

Then this is the wrong approach.  Use a systemd service.  For the case of `mount -a` that is included in the system services already - why do you need to do this again?

You know, I had a feeling that there was a better way to do this. That did the trick!

Oh, and to answer your question, it's so I can access the C: drive of my Windows gaming rig from Linux if needed.

Offline

#5 2020-09-17 22:57:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,517
Website

Re: [SOLVED] Run command in sudo without being prompted for a password.

Then you don't even need a new service - just add a line for it in your fstab.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB