Last active
February 23, 2020 13:43
-
-
Save stigok/351629fb4f570da187e156c20342766d to your computer and use it in GitHub Desktop.
Automatically set permissions on uploaded files and folders to use in, for example, multi-user FTP environments where different clients set different permissions, or otherwise ignore umask.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# [email protected] Oct 2019 | |
# | |
# Reference: | |
# http://positon.org/a-solution-to-the-umask-problem-inotify-to-force-permissions | |
set -x | |
# Take the directory name as argument | |
inotifywait -mrq -e CREATE --format %w%f "$1" | while read FILE | |
do | |
if [ -d "$FILE" ] | |
then | |
# $FILE is a directory | |
chmod 755 "$FILE" | |
else | |
# Treat $FILE as a file | |
chmod 644 "$FILE" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Sets permissions of all uploaded files (644) and folders (755) | |
After=sshd.service | |
[Service] | |
Type=simple | |
WorkingDirectory=/srv/sftp | |
ExecStart=/usr/local/bin/inotify-set-permissions.sh . | |
Restart=on-failure | |
RestartSec=5 | |
[Install] | |
WantedBy=default.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment