20

I am trying to migrate my website data to a new server and keep getting this error. I set up public key access and was able to complete rsync with a .txt file I then wanted to try a directory and it isn't working. This is my first time using rsync so please let me know if you need more information.

Edit: both are remote servers the old is Ubuntu 14.04.4 and the new is Ubuntu 18.04.3

I have sudo permissions on each but I probably dont own the directory I am trying to move. I don't know how to find out.

$ rsync -rt /var/www [email protected]:/home
rsync: recv_generator: mkdir "/home/www" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
rsync: readlink_stat("/var/www/vhosts/testing.site.org/wp-config.php") failed: Permission denied (13)
rsync: readlink_stat("/var/www/vhosts/testing.site.org/wp-mail.php") failed: Permission denied (13)
rsync: readlink_stat("/var/www/vhosts/testing.site.org/wordpress") failed: Permission denied (13)
rsync: readlink_stat("/var/www/vhosts/testing.site.org/wp-signup.php") failed: Permission denied (13)
rsync: readlink_stat("/var/www/vhosts/testing.site.org/wp-trackback.php") failed: Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]
3
  • create /home/www on the remote system, make sure kiana has write permissions for it. then re-run the rsync command.
    – Grump
    Sep 11, 2019 at 14:46
  • Btw I had this issue but it was I accidentally typed copy to root (/) instead of home.
    – qwr
    Apr 29, 2022 at 20:42
  • 1
    Thanks for the great question. I seem to have the same problem, but no answers have helped me. Probably my own fault. Just wanted to point out that while rsync gives this permission error, scp -r will work just fine for the same files going into the same destination. I guess I'm just too dumb to understand the superior permission analysis that rsync performs Jun 3, 2023 at 16:29

3 Answers 3

10

This part here:

rsync: recv_generator: mkdir "/home/www" failed: Permission denied (13)

seems to say that the user kiana does not have sufficient permission on the /home-folder of the remote server in order to write to it.

How to check folder permissions

Performing ls -l | grep home from / on the remote server should give you a tell of who owns the folder and what access permissions it has. Standard for the home-folder is that root:root owns it with 755 as folder permissions (read more about folder and file permissions here)

$ ls -l | grep home
drwxr-xr-x   3 root root  4096 21 mar 14.24 home

This output states that the user root with group root owns the folder (d) home and has full permission (rwx), while others of the group root as well as others has read/execute permission (r-x) but not write permission.

A user having sudo-rights means that said user may temporarily have root-privileges after authentication, which is not really plausible with rsync.

Conclusion

As you are not the actual root user performing the rsync (which by security reasons you shouldn't be), you do not have write-permission on /home folder. I would suggest that you try to save the webserver data in another place where user kiana may be able to write (e.g. /tmp/, /opt/ etc).

4

Another solution is to add --rsync-path="sudo rsync" to the local rsync command. Then your next problem is, that you cannot type on the remote server (no tty, no interactive prompt). At least one workaround for that is to temporarily set NOPASSWD: (insecure: no password to sudo!) at the sudoers line for your user. Once the rsync command is running, you can remove the insecure config.

Someone first needs to have logged into your server to abuse the temperate sudo insecurity. But weigh the pros and cons.

2

The is directory permissions /home is typically only writeable by root.
For example, running ls on my machine shows root/root:

$ ls -laF /home
total 12
drwxr-xr-x  3 root     root     4096 Aug 20  2018 ./
drwxr-xr-x 24 root     root     4096 Sep  3 09:00 ../

Your best option is to create a directory in /home by ssh'ing into that machine running:

#Note the sudo, or you'd have to su to root
sudo mkdir /home/www 
#Then change the ownership so the user kiana can write to it:
sudo chown kiana:kiana /home/www

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .