2

I have a python script on raspberryi pi 3. I want to make it only executable for x user without having root permission. It can not be readable and writable. How can I do that? I gave only x(execute) permission to the file for x user. But when I execute the script, it wants root password.

Onur94
  • 51
  • 3
  • Please add the script if you want efficient help – PRMoureu Jul 13 '17 at 20:29
  • 2
    Linux never requests a password just for executing a script. It will either deny or allow without prompting. Something *in* your script is causing the password prompt, which you have not provided any details on. – jordanm Jul 13 '17 at 20:30
  • The script is not important for example print("test"). Actually I want to make unreadable my codes for x user. Can I do that with changing x user permission? – Onur94 Jul 13 '17 at 20:41

1 Answers1

1

If the user has access to the script, he can modify the content himself. However, just for the sake of the answer or method, we can do something like this:

You can restrict the access to the script by getting the username of the person on the operating the system:

import getpass
if getpass.getuser() in ['user1','user2'] # allowed user list:
    main() # main function
else:
    print("You are not authorised to run this script")
Rajan Chauhan
  • 1,378
  • 1
  • 13
  • 32
  • I can do that but user can read this script. I want to make unreadable script. – Onur94 Jul 13 '17 at 20:45
  • @Onur94 You could always use base64, or encode it in different formats and then use exec() to run the code. However, if the user looks at the script, he may be able to decrypt it. Take a look at this: https://stackoverflow.com/questions/261638/how-do-i-protect-python-code – Rushil Srivastava Jul 13 '17 at 20:51
  • Again, if the user has even a little knowledge of python, they can look at your code. However, you can make it a bit tough by using zlib, and base64. – Rushil Srivastava Jul 13 '17 at 20:55