Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssh 阻止rsync尝试请求密码_Ssh_Rsync - Fatal编程技术网

Ssh 阻止rsync尝试请求密码

Ssh 阻止rsync尝试请求密码,ssh,rsync,Ssh,Rsync,如何防止rsync尝试为远程服务器登录请求密码 注意:我不是问如何设置经过公钥验证的SSH。我知道如何设置经过身份验证的公钥SSH。我要问的是,如果公钥身份验证失败,如何防止rsync尝试请求密码,就像scp的-B标志所做的那样。我在这里的脚本中使用了rsync,因此如果它试图请求密码,我的脚本将挂起,等待永远不会出现的输入。我想让rsync命令失败,这样我的脚本就可以检测到失败并优雅地退出。只需将选项传递给rsync使用的底层ssh命令: rsync -e 'ssh -oBatchMode=y

如何防止
rsync
尝试为远程服务器登录请求密码


注意:我不是问如何设置经过公钥验证的SSH。我知道如何设置经过身份验证的公钥SSH。我要问的是,如果公钥身份验证失败,如何防止
rsync
尝试请求密码,就像
scp
-B
标志所做的那样。我在这里的脚本中使用了
rsync
,因此如果它试图请求密码,我的脚本将挂起,等待永远不会出现的输入。我想让
rsync
命令失败,这样我的脚本就可以检测到失败并优雅地退出。

只需将选项传递给
rsync
使用的底层
ssh
命令:

rsync -e 'ssh -oBatchMode=yes [other ssh options]' [rest of rsync command]
rsync
手册:

ssh
手册:

这模拟了bahavior os
scp-B

-e, --rsh=COMMAND           specify the remote shell to use
BatchMode

If set to “yes”, passphrase/password querying will be disabled.
This option is useful in scripts and other batch jobs where no
user is present to supply the password.  The argument must be
“yes” or “no”.  The default is “no”.