[SOLVED] allow users to execute a Python File but not read
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a way to change the sensitive contents to a compiled language then just call that from your python file? Then the stuff they don't need to see or know is hidden in the object file of whatever you call.
That allows the empty group 'piy' to run the script but since no accounts are in it, only those in the group 'change' can run the script via sudo with the -g option. The "" means that the script must be run without any options. Then add people to the group 'change' who you want to run the script.
Code:
sudo -g piy /usr/local/bin/script.py
That can be wrapped in a script, an shell alias, or a shell function for a shortcut.
Last edited by Turbocapitalist; 10-17-2023 at 01:08 AM.
Reason: link to compiling python
It will be a security risk by allowing all users as sudoer to run the file.
No, why? If you allow anyone to run only that single command. Otherwise you can write a shell script, which will execute the python script (with config and whatever required) and you need to allow to execute only that shell script.
Quote:
Originally Posted by JJJCR
Any other methods to do this? allow user to run/execute the Python file but don't allow them to view the contents of the file. Thanks.
The files which are used by script languages should be readable, because the interpreter is the real executable and it needs to read the script itself (using the credentials of the current user). You might try a setuid executable, but it is definitely not secure, not better than the sudoer setup.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.