Linux

rsync 無法使用 -o StrictHostKeyChecking=no 選項

  • September 26, 2022

下面的 rsync 工作並幫助將遠端目錄複製到本地主機

/bin/rsync -rv myremoteuser@myremotehost:/tmp/Deployments/ /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/

一旦我添加-o StrictHostKeyChecking=no它失敗並出現以下錯誤:

/bin/rsync -rv -o StrictHostKeyChecking=no myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/
Unexpected remote arg: myremoteuser@myremotehost:/tmp/Deployments
rsync error: syntax or usage error (code 1) at main.c(1348) [sender=3.1.2]

我希望它能夠工作並且當我將它放在雙引號下時也能工作,如下所示:

"/bin/rsync -rv -o StrictHostKeyChecking=no myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/"
bash: /bin/rsync -rv -o StrictHostKeyChecking=no myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/: No such file or directory

以下是詳細資訊:

$ /bin/rsync --version
rsync  version 3.1.2  protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
   64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
   socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
   append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
[mylocaluser@mylocalhost myremotehost]$ uname -a
Linux mylocalhost 3.10.0-1160.76.1.el7.x86_64 #1 SMP Tue Jul 26 14:15:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

-oRsync在其命令行上不採用 ssh選項。您必須將 ssh 選項放入傳遞給 rsync-e選項的 ssh 命令字元串中。就像是:

/bin/rsync -rv -e 'ssh -o StrictHostKeyChecking=no' myremoteuser@myremotehost:/tmp/Deployments /web/playbooks/automation/getfiles/tmpfiles/4/E5EA787E/myremotehost/

正如您所提到的,您應該能夠將上述內容用雙引號括起來,因為-e參數是單引號。手冊頁還提到使用RSYNC_RSH環境變數作為-e命令行選項的替代方案。

引用自:https://unix.stackexchange.com/questions/718818