Answer the question
In order to leave comments, you need to log in
How to change the owner and permissions of a file using python?
Good afternoon, I'm trying to change the rights and user on a file in Linux with the following script:
#!/usr/bin/python3
import os, grp, pwd
uid = pwd.getpwnam("myuser").pw_uid
gid = grp.getgrnam("myuser").gr_gid
os.chmod("/tmpjcef-p11500_scheme.tmp", 0o777)
os.chown("/tmpjcef-p11500_scheme.tmp", uid,gid)
Traceback (most recent call last):
File "/home/myuser/PycharmProjects/proj5/main.py", line 15, in <module>
os.chmod("/tmpjcef-p11500_scheme.tmp", 0o777)
PermissionError: [Errno 1] Operation not permitted: '/tmpjcef-p11500_scheme.tmp'
Answer the question
In order to leave comments, you need to log in
777 changes permissions for root too, so you need to run the script from under sudo to change it. Or you can look at other flags instead of 777 that do not require root rights
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question