无法弄清楚如何关闭 StrictHostKeyChecking

Ste*_*ieD 3 ssh

我在不同的数据库上运行了这个 ssh 命令:

ssh -i $8 -l $9 $1 "set -o pipefail set -o StrictHostKeyChecking=no; mysqldump --single-transaction --skip-lock-tables -u $2 -p$3 -P $4 -h $5 $6" | gzip -c > $7;

这些变量是该命令的参数。

它可以工作,除非 IP 地址的后端发生变化,尽管有set -o StrictHostkeyChecking=no,我收到以下消息:

Offending ECDSA key in /home/admin/.ssh/known_hosts:130
  remove with:
  ssh-keygen -f "/home/admin/.ssh/known_hosts" -R "172.30.0.63"
ECDSA host key for 172.30.0.63 has changed and you have requested strict checking.
Host key verification failed.
Run Code Online (Sandbox Code Playgroud)

命令有问题,但我不确定哪里有问题。我尝试了几种不同的变体,但没有成功。

ste*_*ver 14

StrictHostKeyChecking=no参数需要作为 ssh 命令的选项传递,而不是作为远程 shell 命令的选项。例如:

ssh -i "$8" -o StrictHostKeyChecking=no -l "$9" "$1"  "
  set -o pipefail; mysqldump --single-transaction --skip-lock-tables -u $2 -p$3 -P $4 -h $5 $6
" | gzip -c > "$7"
Run Code Online (Sandbox Code Playgroud)

(我在这里对参数扩展进行了双引号,因为尽管您没有提及您正在使用哪个本地 shell,但许多 shell 都会对分词和文件名生成进行未加引号的扩展。)

请注意,此选项不会抑制有关可能的 MiM 攻击的警告。