I'm trying to make this directory /var/machine/hi'
by running this in Python:
os.mkdir("/var/machine/hi")
However, I'm getting a
OSError: [Errno 13] Permission denied: '/var/machine/hi'
I have tried the following:
chmod 777 /var/machine
and chmod 777 /var
The owners for /var
is root
wheel
The owners for /var/machine
is root
wheel
How can I fix/debug this?
mkdir: cannot create directory – Permission denied. This is another very common error when creating directories using mkdir command. The reason for this error is that the user you’re running the mkdir as, doesn’t have permissions to create new directory in the location you specified.
By default, directories on a Linux system will have 0775 or drwxrwxr-x permssion and will be owned by the user that created the directory. In this example, root has read/write/execute permission, and every other user has read and execute, but not write permission.
This error suggests that the directory name you’re using (/tmp/try in my example shown on the screenshot) is already taken – there is a file or a directory with the same name, so another one can’t be created. You can use the wonderful ls command to check what’s going on: Sure enough, we have a directory called /tmp/try already!
Have you tried using os.system with a sudo command on the operation only?
os.system("sudo mkdir /var/machine/hi")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With