I have a directory in my Debian home: /home/myuser/pchome/ which i want to use as a mount point for a remote cifs filesystem. So i have a bash script, which is run on every myuser login. This script contains the command:mount -t cifs //192.168.1.2/myuser -o username=myuser,password=mypassword,uid=1000,gid=1000 /home/myuser/pchomeThe command works like a charm using itself in a console. But, the problem is that mount requires sudo and password introduction (or be run with root privileges).sudoersFirst approach i thought about is configure the sudoers to allow the use of mount for myuser. Something like:myuser ALL=(ALL)    NOPASSWD: /bin/mount, /bin/umountThe problem with that, is that myuser could use mount without limits, even for mounting filesystems on /etc, for example. I'm not interested in allowing myuser the use of mount command freely.fstabSecond approach i thought about, is using fstab to allow the mount. I did not test it, but i think that, with this solution, both the mount point and filesystem to mount could be fixed, and no other mount could be done. But, every user could perform the mount (if using the user option for fstab line).From my point of view, none of the two ideas is correct enought, so i would like if any of you knows the valid approach to that problem.I only want to be allowed to mount a public remote filesystem using a mount point inside my home without any concern about security, passwords or exposing the system to malicious mounts. It should be easier, since the mount point is inside my own home.Thanks in advance.
Automate a mount without linux password to mount a remote cifs filesystem
debian;mount;cifs
One possibility is to save the mounting command as a script (modifiable only by root) AND define sudo privileges for the script./home/bin/mymount:#!/bin/shmount -t cifs //192.168.1.2/myuser -o username=myuser,password=mypassword,uid=1000,gid=1000 /home/myuser/pchomesudoers:myuser ALL=(ALL)    NOPASSWD: /home/bin/mymount # and maybe , /home/bin/myumountAs a sidenote, you may also want to save that CIFS password in a credentials file.You can give the permission to various users by defining an alias or by giving the permission to a group.Using an alias:User_Alias CIFSUSERS = myuser, user2, user3 #, more usersCIFSUSERS ALL=(ALL)    NOPASSWD: /home/bin/mymount # ...Or giving permission to a group, e.g. group floppy:%floppy ALL=(ALL)    NOPASSWD: /home/bin/mymount # ...