【问题标题】:Bash shell scripting for answering the questions of SSH key generation用于回答 SSH 密钥生成问题的 Bash shell 脚本
【发布时间】:2013-04-14 14:02:35
【问题描述】:

我想回答那个出现在 bash shell 中的问题

例如:

在脚本中

#!/bin/bash
ssh-keygen -t rsa

#it will appear a question >> Enter file in which to save the key 
# (/root/.shh/id_rsa) so how  can i read answer from the user(which is the path)
# and **enter it to be the answer of the question.

【问题讨论】:

    标签: shell scripting public-key-encryption ssh-keys openssh


    【解决方案1】:

    尝试这样做(无需使用STDIN):

    rm -f ~/.ssh/id_rsa*
    ssh-keygen -q -t rsa -P MyOwnPassPhrase -f ~/.ssh/id_rsa
    

    你读过吗

    man ssh-keygen 
    

    ? =)

    【讨论】:

      【解决方案2】:

      如果您已经知道要存储输出的文件的名称,则可以在脚本的命令行中指定,如下所示:

      ssh-keygen -t rsa -f keyfile
      

      否则,您可以要求用户指定名称,否则使用提供的参数。如果他们没有在命令行上传递名称,此方法将允许他们指定名称。 (用法是:your-scriptname keyfile-name)

      if [ $# -eq 0 ]; then
              read -p "Enter filename for key: " keyfile
              ssh-keygen -t rsa -f $keyfile  
      else
              ssh-keygen -t rsa -f $1 
      fi
      

      【讨论】:

        猜你喜欢
        • 2021-05-13
        • 1970-01-01
        • 2014-07-07
        • 1970-01-01
        • 2017-01-09
        • 1970-01-01
        • 1970-01-01
        • 2013-03-17
        • 1970-01-01
        相关资源
        最近更新 更多