I have a Python script that needs to mount disks on an Ubuntu server without root privileges.
I made the script executable (with #!/usr/bin/env python
). I also renamed it to '.sh' (probably not important), and chmod
it to be executable.
Then, I entered the following line to my sudoers file:
ALL ALL = (ALL) NOPASSWD: /home/sazulay/.scripts/mount_disks.sh/
If I remove the last '/' ,visudo claims I have a syntax error.
If I leave it like that and run the following line from my user:
sudo /home/sazulay/.scripts/mount_disks.sh
I am still prompted for password, which was exactly what I was trying to avoid.
What am I doing wrong?
There shouldn't be a slash at the end of the line. Your sudoers file should look like this,
ALL ALL = (ALL) NOPASSWD: /home/sazulay/.scripts/mount_disks.sh
Now, on to your actual problem!
If I remove the last '/' ,visudo claims I have a syntax error.
I suspect that the line you added is at the end of the file. Now, traditionally, unix commands have a problem if a file does not end with a newline \n
. Most of the linux editors (that I know off) add this in. There may be a possibility that whatever editor you're using does not. So add an extra line at the end of the file so your line is not the last line. So it should be something like this
ALL ALL = (ALL) NOPASSWD: /home/sazulay/.scripts/mount_disks.sh
<--- empty line --->