douzhang1955 2014-04-11 12:02
浏览 35
已采纳

错误输出而不是用SSH要求密码

I'm writing a script that uses rsync, and I want it to error out if the SSH key has a password, telling the user to use a non-password protected key instead (as the script runs in the background).

However, none of the flags I've tried for SSH do this, and I've found nothing in the man pages.

What's the best way to disable the passphrase prompt for SSH?

  • 写回答

1条回答 默认 最新

  • dongxun7301 2014-04-11 12:23
    关注

    You can do this using the BatchMode option. This will cause SSH to avoid anything that may cause a script to hang, such as password/passphrase prompts.

    This example is taken directly from a similar question asked at http://www.unix.com/programming/184775-test-ssh-but-do-not-return-password-prompt.html

    if ssh -o BatchMode=yes "$hostname" true 2>/dev/null; then
        echo "it works"
    else
        echo "it's broken."
    if
    

    Here's an example with rsync:

    rsync -e "ssh -o BatchMode=yes -i /var/www/.ssh/id_rsa" /path/to/test/file.txt remotehost:/path/to/test/file.txt
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记