使用不同于ssh密钥所有者的用户,使用rsync + ssh + public key同步本地和远程目录 [英] Syncing local and remote directories using rsync+ssh+public key as a user different to the ssh key owner

查看:193
本文介绍了使用不同于ssh密钥所有者的用户,使用rsync + ssh + public key同步本地和远程目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标是通过ssh同步本地和远程文件夹。

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

我当前的用户是 user1 ,而且我没有密码通过ssh访问设置到服务器 server1
我想通过 rsync 实用程序将本地文件夹与 server1 上的文件夹同步。
通常我会运行:

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 访问按预期工作, rsync 可以通过 ssh 连接,但是返回Permission denied错误,因为在 server1 文件夹 / path / to / remote / folder user2 拥有: user2 。该文件夹的文件权限不允许任何其他人更改。
user1 server1 上的sudoer,所以 sudo su - user2 ssh 会话期间。
如何在 rsync 中切换用户,当 ssh 发送到服务器时

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?

user1 添加到组 user2 不是一个选项,因为服务器上的所有用户/组管理都是自动完成的,每X分钟从中央回购复制,我没有访问。

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.

我想到的可能解决方案是将本地文件夹与服务器上的 user1 所拥有的临时中间远程文件夹同步的脚本,然后将两个远程文件夹同步为用户2

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.

推荐答案

我没有尝试过,但是如何使用rsync的'--rsync-path'选项?

I have not tried it by myself, but how about using rsync's '--rsync-path' option?

rsync -rtvz --rsync-path='sudo -u user2 rsync' /path/to/local/folder server1:/path/to/remote/folder

这篇关于使用不同于ssh密钥所有者的用户,使用rsync + ssh + public key同步本地和远程目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆