Rsync shell script permission error on destination server

Posted on

Rsync shell script permission error on destination server – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, ubuntu, rsync, , .

So this is my first bash script attempt, and I am trying to rsync a project folder on OS X to a development server running ubuntu 14.04. I get some permission errors on the destination server when I try to rsync as my user ‘developer’ but I also got them when I did it as user ‘ubuntu’. I cannot try as root due to default cloud server settings on EC2.

Here is my shell script.

rsync -r —l -t -z -v -e "ssh" --exclude “/Applications/MAMP/htdocs/finalall/nbproject/” --delete /Applications/MAMP/htdocs/finalall/ :/var/www/html
afplay "/System/Library/Sounds/Morse.aiff"

This is my error:

building file list ... rsync: link_stat "/Users/xxxxx/?#200#224l" failed: No such file or directory (2)
IO error encountered -- skipping file deletion
rsync: failed to set times on "/var/www/html/.": Operation not permitted (1)
rsync: recv_generator: mkdir "/var/www/html/nbproject" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
rsync: mkstemp "/var/www/html/.testerterst.php.TISozV" failed: Permission denied (13)

sent 493 bytes  received 54 bytes  1094.00 bytes/sec
total size is 971  speedup is 1.78
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]

here is (some of) the output of sudo cat /etc/group


Sincere thanks for any help. It is greatly, greatly appreciated.

The output to ls -lZd / /var/ /var/www/ /var/www/html/ is:

drwxr-xr-x 22 root root ? 4096 Aug  5 19:53 /
drwxr-xr-x 13 root root ? 4096 Aug  5 20:00 /var/
drwxr-xr-x  3 root root ? 4096 Aug  5 20:00 /var/www/
drwxr-xr-x  2 root root ? 4096 Aug  5 20:17 /var/www/html/

Solution :

You don’t have write access to the /var/www/html on the destination server, since the folder belongs to root and everybody else only has read/execute rights.

The best way to fix this is changing the owner of that directory to your ssh user:

chown -R developer. /var/www/html

This changes the owner of /var/www/html and all its subdirectories to the developer user and his default group.

If still others users need write access to the same directory I would recommend putting them in one group and then change the permissions of the folder to also allow everyone in the same group write access. The followings show you how to do that.

groupadd devs #Adds a group called devs

useradd -G devs ubuntu #Adds the devs group to the ubuntu user

chown -R .devs /var/www/html #Changes only the group of the directory to devs

chmod -R 775 /var/www/html #Allows the owner and group of the directory full access, everybody else only has read/execute

Rather than change directory ownership, you could do this in two stages:

  1. rsync
  2. ssh with a command tacked on to the end.

Assuming theserver is defined in your local ~/.ssh/config:

# rsync sourceDir to the home dir of yourname on theserver.
# ':' after 'theserver' invokes ssh as transport.
$ rsync -<options> sourceDir yourname@theserver:.

# You will be prompted for your theserver password for the cp.
# Change the cp source and dest to suit your needs.
$ ssh -t theserver "sudo cp -r sourceDir /var/www/. && rm -rf sourceDir"

Leave a Reply

Your email address will not be published.