如何在不要求密码提示的情况下自动进行 rsync

发布于 2024-08-29 20:20:05 字数 1459 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

昵称有卵用 2024-09-05 20:20:05

您不需要这样做 - 只需设置一对 ssh 密钥并将公钥放在远程系统的 .ssh 目录中。

然后你只需执行以下操作:(

rsync -a -e ssh /local/path/ server:/remote/path/

注意,-e ssh 已经成为默认值很多年了,因此你可以忽略它,除非你使用的是非常旧的版本。)

此处有关设置密钥的“如何”指南。

You don't need to do that - just need to set up a pair of ssh keys and put the public key in the remote system's .ssh directory.

Then you just do this:

rsync -a -e ssh /local/path/ server:/remote/path/

(Note that -e ssh has been the default for quite a few years now, so you can probably omit it, unless you're using a very old version.)

There's a "how to" guide on setting up the keys here.

最冷一天 2024-09-05 20:20:05

如果您希望它在 cron 中工作,您有几种可能性:

  • 设置无密码 ssh 密钥 - 不是很安全
  • 设置无密码 ssh 密钥,但将它们与authorized_keys 文件中的 ssh ForceCommand 结合起来,以限制可以运行的命令那个 ssh 密钥。请参阅 man sshd、google 上的“ssh ForceCommand”
  • 设置密码 ssh 密钥,但将它们与钥匙串结合起来,以在会话之间将密钥保留在内存中。我写了一篇关于此的博客文章: ssh、ssh-agent、钥匙串和 cron 注释

If you want this to work from cron, you have several possibilities:

  • setup password-less ssh keys - not very secure
  • setup password-less ssh keys, but combine them with ssh ForceCommand in the authorized_keys file to limit the commands that can be run with that ssh key. See man sshd, google on "ssh ForceCommand"
  • setup passworded ssh keys, but combine them with keychain to keep the key in memory between sessions. I've written a blog post on this: ssh, ssh-agent, keychain and cron notes
扛起拖把扫天下 2024-09-05 20:20:05

如果您想远程复制文件:

  1. 请确保您的本地计算机上有一个可以登录远程计算机的公钥。(在本例中,我的 ssh-key 是“/home/myaccount/.ssh/id_rsa”
  2. 指定本地您想要与远程同步的文件夹,在我的例子中为“/home/myaccount/mysourcefolder”
  3. 指定远程服务器中的目标文件夹完整路径,在我的例子中为remoteaccount@remoteserver:“/home/remoteaccount/mydestinationfolder/”

注意:

  • - -progress 是显示正在复制的每个文件的进度
  • -a 重复传输 mysourcefolder 中的所有文件
  • -v 表示详细程度
  • -z 压缩小文件的数据部分

我的命令如下所示:

rsync -avz --progress -e "ssh -i /home/myaccount/.ssh/id_rsa"
/home/myaccount/mysource 文件夹
Remoteaccount@remoteserver:“/home/remoteaccount/mydestinationfolder/”

If you want to copy files remotely:

  1. Make sure you have a public key on your local machine that can log into the remote machine.(in this case the my ssh-key is "/home/myaccount/.ssh/id_rsa"
  2. Specify local folder you want to sync with the remote, in my case "/home/myaccount/mysourcefolder"
  3. Specify the destination folder full path in the remote server, in my case remoteaccount@remoteserver:"/home/remoteaccount/mydestinationfolder/"

Note:

  • --progress is to show progress for each file being copied
  • -a to transfer recusively all files in the mysourcefolder
  • -v for verbosity
  • -z to compress data portions for small files

My command will look like below:

rsync -avz --progress -e "ssh -i /home/myaccount/.ssh/id_rsa"
/home/myaccount/mysourcefolder
remoteaccount@remoteserver:"/home/remoteaccount/mydestinationfolder/"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文