Brad Fallon
Brad Fallon

Reputation: 169

On linux, how can I allow any user to write to a file, but only by running my (python) script?

I'm working on a GUI for managing the contents of a specific network folder. The files are created/deleted and moved by a script.

I have a json index file that has information about the files in this folder.

Is there a way to give all users write permission to these files, but only if they use my script?

I'm not worried about security, just don't want people to edit files without the index file being updated.

Upvotes: 1

Views: 277

Answers (2)

Martijn de Munnik
Martijn de Munnik

Reputation: 986

You're program needs the SUID bit set https://en.wikipedia.org/wiki/Setuid. I'm not sure if this can be done with a python script.

Upvotes: 1

willpnw
willpnw

Reputation: 775

You can specify this type of thing using visudo.

From: http://www.atrixnet.com/allow-an-unprivileged-user-to-run-a-certain-command-with-sudo/

First, you’ll need to use the visudo utility…

    sudo visudo

This command safely opens up the /etc/sudoers file for you in your default editor. Let’s say you want to allow a user named “joe” to run a given command. You just need to add a line like this below (customize for your needs)

    joe ALL=(ALL) NOPASSWD: /full/path/to/command

Now what if you want to restrict joe to only use that command within a given set of parameters or with only certain arguments? Well, just toss them in there too! Check this out:

    joe ALL=(ALL) NOPASSWD: /full/path/to/command ARG1 ARG2

Upvotes: 2

Related Questions