I need to allow a specific user to download files from my web server. The files will be in a specific directory and I don't want the downloader to read, write or do anything outside of that directory. So, I created a regular user - let's call her Downloader - on a Debian 11 server. I used the -d option to point that user's home directory to /var/www/example.com/Downloader
useradd -m -d /var/www/example.com/Downloader Downloader
All files in the example.com directory and below have permissions assigned as follows:
sudo chown -R WebAdmin /var/www/example.com/
sudo chgrp -R www-data /var/www/example.com/
sudo chmod -R 750 /var/www/example.com/
sudo chmod g+s /var/www/example.com/
and I further modified the Downloader directory as follows:
cd /var/www/example.com/Downloader
sudo chgrp -R Downloader ./
sudo chmod -R 750 ./
sudo chmod g+s ./
So now the permission look like this:
-rwxr-x--- 1 WebAdmin Downloader 740 Apr 11 11:33 index.php
When I tried the command:
rsync -arzvP [email protected]:/var/www/example.com/Downloader/ ./
I get an error:
Could not chdir to home directory /var/www/example.com/Downloader/: Permission denied
receiving incremental file list
rsync: [sender] change_dir "/var/www/example.com/Downloader" failed: Permission denied (13)
sent 8 bytes received 9 bytes 1.79 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1677) [Receiver=3.1.3]
rsync: [Receiver] write error: Broken pipe (32)
I understand that user Downloader cannot traverse the parent directories, /var/www etc. but I thought making the home directory the /var/www/example.com/Downloader would fix it.
BTW, I also tried
rsync -arzvP [email protected]:/ ./
and it basically started downloading from the root folder (including the boot dev and other directories)! I of course don't want that!
So, how do I achieve the desired result?