Tác giả: Dương Nguyễn Phú Cường
Ngày đăng:
30/10/2025, 21:21
Lượt xem: 163
#!/bin/bash
# Purpose: Set file permission to read-only
# Author: nixCraft <www.cyberciti.biz> under GPL v2.0+
# ---------------------------------------------------------------
# DocumentRoot permissions
_dp="0544"
_fp="0444"
_sp="0744"
# Apache user/group
_user="www-data"
_group="www-data"
## If $1 is not passed, set to the current working dir using $PWD
_dir="${1:-${PWD}}"
## Die if $dir does not exists
[ ! -d "$_dir" ] && { echo "Error: Directory $_dir not found."; exit 2; }
## Get confirmation
echo "I will change file permission for the webserver dir and files to restrictive read-only mode."
read -p "The current working dir is ${PWD}. Are you sure (y / n) ?" ans
## Lowercase $ans and compare it
if [ "${ans,,}" == "y" ]
then
chown -R ${_user}:${_group} "$_dir"
chmod -R $_fp "$_dir"
fi