Linux
rsync 無法使用 -o StrictHostKeyChecking=no 選項
下面的 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
-o
Rsync在其命令行上不採用 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
命令行選項的替代方案。