8

The goal is to sync local and remote folders over ssh.

My current user is user1, and I have a password-less access setup over ssh to a server server1. I want to sync local folder with a folder on server1 by means of rsync utility. Normally I would run:

rsync -rtvz /path/to/local/folder server1:/path/to/remote/folder

ssh access works as expected, rsync is able to connect over ssh, but it returns "Permission denied" error because on server1 the folder /path/to/remote/folder is owned by user2:user2. File permissions of the folder do not allow it to be altered by anyone else. user1 is a sudoer on server1 so sudo su - user2 works during ssh session. How to forse rsync to switch the user when it ssh'ed to the server?

Adding user1 to the group user2 is not an option because all user/group management on the server is done automatically and replicated from a central repo every X mins, that I have not access to.

Same for changing permissions/ownership of the destination folder: it is updated automatically on a regular basis with a reset of all permissions.

Possible solution coming to my mind is a script that syncs the local folder with a temporary intermediate remote folder owned by user1 on the server, and then syncs two remotes folders as user2.

Googling for a shorter and prettier solution did not yield any success.

4

3 に答える 3

6

自分では試していませんが、rsyncの「--rsync-path」オプションを使ってみてはどうでしょうか?

rsync -rtvz --rsync-path='sudo -u user2 rsync' /path/to/local/folder server1:/path/to/remote/folder
于 2013-01-16T23:51:56.537 に答える
1

アクセス許可の問題を解決するには、user2 としてリモートでログインする SSH セッションで rsync を実行する必要があります。

rsync avz -e 'ssh -i privatekeyfile' /path/to/local/folder/ user2@server1:/path/to/local/folder

次の回答は、SSH キーのセットアップ方法を説明しています。

于 2013-01-16T21:49:50.183 に答える
0

user1がuser2@server1にアクセスするためのパスワードなしのアクセスを設定してから、次の手順を実行します。

rsync -rtvz /path/to/local/folder user2@server1:/path/to/remote/folder
于 2013-01-16T04:20:08.403 に答える