Check your current file/directory permission with:
stat -c "%a" /path/to/dir_or_file
To recursively give directories read&execute privileges:
find /path/to/base/dir -type d -exec chmod 755 {} +
To recursively give files read privileges:
find /path/to/base/dir -type f -exec chmod 644 {} +
Or, if there are many objects to process:
chmod 755 $(find /path/to/base/dir -type d)
chmod 644 $(find /path/to/base/dir -type f)
Or, to reduce chmod spawning:
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
Source:
- https://superuser.com/questions/91935/how-to-recursively-chmod-all-directories-except-files
- https://docs.python.org/3/library/os.html#files-and-directories
- https://docs.djangoproject.com/en/dev/ref/settings/#file-upload-directory-permissions
You can create a more secure set of permissions if you know your environment
and combine who owns the directories/files with chown
and then who can do what with chmod
.
In case you need to really ensure how Django will behave when creating directories and files:
settings.py
FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755
FILE_UPLOAD_PERMISSIONS = 0o644
It is important that the values are in ocatal base. (prefix 0o
).