Helldrak
Helldrak

Reputation: 59

Bash sudo script without prompting for password – Manjaro NFS mounting

I’ve been searching for some time why my sudo configuration is not working to mount a local NAS server via NFS, without prompting for password – all the more that it has worked for years under Fedora and seems not to work with the same configuration under Manjaro. The idea is simply to allow my wife to mount files at will, without remembering complex passwords and in order to avoid relying on fstab, so as not to slow boot time when not on the local network. The script is simple enough and consists of a list of folder like this :

```bash
#!/bin/bash
mount -t nfs 192.168.X.X:/volume1/manon /mnt/NAS/manon -o auto,user,rw,noatime
# more folders…
exit 0
```

It is of course working as intended when used with sudo, and giving user password (also with a convenient bashrc alias). Then, I’ve followed the arch wiki (https://wiki.archlinux.org/index.php/Sudo#Example_entries) to apply the NOPASSWD to my user on the intended script with this line (I also tried to add the pacman system update for our purpose here) :

```
manon ALL=(ALL) NOPASSWD: /home/manon/.script/NASNFS.sh,/usr/bin/pacman -Syyu
```

which is confirmed by sudo -lu :

```console
[manon@manonPC ~]$ sudo -lU manon
L'utilisateur manon peut utiliser les commandes suivantes sur manonPC :
    (ALL) NOPASSWD: /home/manon/.script/NASNFS.sh, /usr/bin/pacman -Syyu
    (ALL) ALL
```

However, it still asks for password – mounting for files or updating system – whatever I do… I also tried to add the hostname to visudo, or use %wheel group (which manon belongs to), without result.

Has anyone any idea of the step I missed and why this is not working like in Fedora ? Thanks for having read, and all the best,

Upvotes: 0

Views: 620

Answers (1)

Helldrak
Helldrak

Reputation: 59

I’ve finally found the answer to my question – I’ll post in case it might be useful to anyone stumbling over the same blunder. As stated in the wiki(https://wiki.archlinux.org/index.php/Sudo#Example_entries):

The most customized option should go at the end of the file, as the later lines overrides the previous ones.

The problem is thus not to rely on the default comments in the visudo file, since there is a final command which could easily be mistaken for a comment – but is not:

#includedir /etc/sudoers.d

This includes a directory which indeed contains a 10-installer file, applying a default behaviour on the wheel group, overriding my custom command:

%wheel ALL=(ALL) ALL

That was why I had sudo -lU manon outputing:

[manon@manonPC ~]$ sudo -lU manon
L'utilisateur manon peut utiliser les commandes suivantes sur manonPC :
    (ALL) NOPASSWD: /home/manon/.script/NASNFS.sh, /usr/bin/pacman -Syyu
    (ALL) ALL

instead of now:

[manon@manonPC ~]$ sudo -lU manon
L'utilisateur manon peut utiliser les commandes suivantes sur manonPC :
    (ALL) ALL
    (ALL) NOPASSWD: /home/manon/.script/NASNFS.sh

In conclusion: beware to add your custom rule in visudo at the very end of the file, or create a new file in the sudoers.d folder, incrementing file name.

Sorry for the noise if that was obvious, and hoping being helpful for others. All the best,

Upvotes: 0

Related Questions