-1

I want to answer the question of that appear in the bash shell

Ex:

at the script

#!/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.
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223

2 Answers2

0

Try doing this (no need to use STDIN):

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

Have you ever read

man ssh-keygen 

? =)

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0

If you already know the name of the file where you wish to store the the output, you cans specify that on the command line in your script as indicated here:

ssh-keygen -t rsa -f keyfile

Otherwise, you can ask the user to specify the name, otherwise use the argument provided. This method will allow them to specify the name if they did not pass it on the command line. (Usage would be: 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
RandomW
  • 11
  • 3