用于回答SSH密钥生成问题的Bash shell脚本

问题描述 投票:-1回答:2

我想回答在bash外壳中出现的问题

例如:

在脚本中

#!/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
2个回答
0
投票

尝试执行此操作(无需使用STDIN):

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

您读过吗

man ssh-keygen 

? =)


0
投票

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

ssh-keygen -t rsa -f keyfile

否则,您可以要求用户指定名称,否则请使用提供的参数。如果他们没有在命令行上传递名称,则该方法将允许他们指定名称。 (用法是:您的脚本名密钥文件名)

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
© www.soinside.com 2019 - 2024. All rights reserved.