Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mkdir permission denied

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?

like image 376
Popcorn Avatar asked Sep 30 '13 19:09

Popcorn


People also ask

Why can’t mkdir create a directory?

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.

What is the default permissions of a directory in Linux?

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.

Why is the Directory I’m using already taken?

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!


1 Answers

Have you tried using os.system with a sudo command on the operation only?

os.system("sudo mkdir /var/machine/hi")
like image 115
sirFunkenstine Avatar answered Sep 30 '22 23:09

sirFunkenstine