From 79d7b4d94b641c7ca10c246a804deeea07e40315 Mon Sep 17 00:00:00 2001 From: Abhay Date: Fri, 1 Aug 2025 17:34:08 +0530 Subject: [PATCH] Fix: Resolve multi-user write permission issues in Samba server - Remove conflicting ownership override in start_samba.sh - Add proper per-user directory ownership in init_users.sh - Update users.conf with actual users and force user/group settings - Enable concurrent write access for all users to their respective directories --- init_users.sh | 16 ++++++++++++++++ start_samba.sh | 5 ----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/init_users.sh b/init_users.sh index 270762c..d82867d 100755 --- a/init_users.sh +++ b/init_users.sh @@ -54,4 +54,20 @@ while IFS=':' read -r username password; do done < <(grep -E '^[^#\[].*:.*' /etc/samba/users.conf) +# Set proper ownership for each user's directory +echo "Setting proper ownership for user directories..." +while read -r line; do + # Look for share section headers [sharename] + if [[ $line =~ ^\[([^]]+)\]$ ]]; then + share_name="${BASH_REMATCH[1]}" + share_dir="/mount/storage/$share_name" + + if [ -d "$share_dir" ] && id "$share_name" &>/dev/null; then + echo "Setting ownership for $share_dir to $share_name:$share_name" + chown -R "$share_name:$share_name" "$share_dir" + chmod -R 775 "$share_dir" + fi + fi +done < /etc/samba/users.conf + echo "User and directory initialization complete." diff --git a/start_samba.sh b/start_samba.sh index dd05452..9176bfa 100755 --- a/start_samba.sh +++ b/start_samba.sh @@ -11,11 +11,6 @@ echo "Using HOST_UID=$HOST_UID and HOST_GID=$HOST_GID" # Initialize users /init_users.sh -# Set proper permissions for storage directory -# Use host user/group IDs for better compatibility -chown -R $HOST_UID:$HOST_GID /mount/storage -chmod -R 775 /mount/storage - # Create log directory mkdir -p /var/log/samba