Setting File Permissions (644/755) and Ownership (root.root) When Using Rsync from Windows to Linux


3 views

When transferring files from Windows to Linux via Rsync, permission handling becomes tricky because:

  • Windows NTFS doesn't support Linux-style permissions natively
  • The default Rsync behavior preserves Windows ACLs rather than applying Unix permissions
  • Ownership information isn't properly transferred between different OS environments

To force specific permissions and ownership, combine these flags:

rsync -avz --no-perms --chmod=Du=rwx,go=rx,Fu=rw,go=r --usermap=*:root --groupmap=*:root /mnt/windows_source/ user@linux-server:/target/path/

Breakdown of key parameters:

--no-perms          : Disable permission preservation from source
--chmod=Du=rwx,go=rx : Set directories to 755 (rwxr-xr-x)
--chmod=Fu=rw,go=r   : Set files to 644 (rw-r--r--)
--usermap=*:root     : Map all users to root
--groupmap=*:root    : Map all groups to root

For automated transfers, create a Windows batch script (rsync_perms.bat):

@echo off
set RSYNC="C:\Program Files\cwRsync\bin\rsync.exe"
set SOURCE="D:\web_content\"
set DEST="user@linux-server:/var/www/html/"

%RSYNC% -avz --no-perms --chmod=Du=rwx,go=rx,Fu=rw,go=r ^
        --usermap=*:root --groupmap=*:root ^
        --exclude='*.tmp' --exclude='Thumbs.db' ^
        --delete %SOURCE% %DEST%

After transfer, verify permissions on Linux:

ssh user@linux-server
sudo find /target/path -type d -exec ls -ld {} \; | head -5
sudo find /target/path -type f -exec ls -l {} \; | head -5

Expected output for directories:

drwxr-xr-x 2 root root 4096 Jan 10 10:00 /target/path/images

Expected output for files:

-rw-r--r-- 1 root root 1024 Jan 10 10:00 /target/path/index.html

Permission denied errors: Ensure the SSH user has sudo privileges or configure sudoers to allow specific rsync commands without password prompts.

Partial permission changes: Some files might retain original permissions if they're open during transfer. Consider a second pass with:

ssh user@linux-server "sudo chmod -R a+rX /target/path"

When transferring files from Windows to Linux via Rsync, permission preservation becomes tricky because NTFS (Windows) and ext4 (Linux) handle permissions differently. The -p flag alone won't work effectively due to fundamental filesystem differences.

For proper permission handling, combine these flags:

rsync -avz --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --no-perms --no-owner --no-group /mnt/windows_source/ user@linux-server:/target/path/

The --chmod flag specifically:

  • Du=rwx: Directories get 755 (owner: rwx, group/others: rx)
  • Dgo=rx: Additional directory permissions specification
  • Fu=rw: Files get 644 (owner: rw, group/others: r)
  • Fgo=r: Additional file permissions specification

Since Windows Rsync clients can't set Linux ownership directly, you have two approaches:

Method 1: Post-transfer chown

# First transfer files
rsync -avz /mnt/windows_source/ user@linux-server:/target/path/

# Then SSH in and change ownership
ssh user@linux-server "sudo chown -R root:root /target/path/"

Method 2: Rsync with sudo on destination

rsync -avz --rsync-path="sudo rsync" /mnt/windows_source/ user@linux-server:/target/path/

For a complete solution combining permission and ownership control:

rsync -avz \
--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r \
--no-perms --no-owner --no-group \
--rsync-path="sudo rsync" \
/mnt/windows_source/ user@linux-server:/target/path/

After transfer, verify permissions with:

ssh user@linux-server "ls -la /target/path/"

Common issues:

  • Passwordless sudo not configured for rsync commands
  • Windows file attributes interfering (use --no-ATTRS if needed)
  • SELinux contexts on Linux (may need restorecon)

For frequent transfers, create a batch script (Windows) or shell script (Linux):

@echo off
set RSYNC="C:\path\to\rsync.exe"
%RSYNC% -avz ^
--chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r ^
--no-perms --no-owner --no-group ^
--rsync-path="sudo rsync" ^
/mnt/windows_source/ user@linux-server:/target/path/