skip to Main Content

I a writing a script. There is a command that colud request to answer yes or no to override a certain file.
I want to automate the script to answer YES or NO ONLY IF the command request it (i don’t want to echo yes inside the command).

The command I am referring to is ssh-keygen, which requires to override the key in case already exists.

In my mind there is something like this…

if (ssh-keygen requests input) --> Sends yes to the ssh-keygen

In particular, I am using the following command:

ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/id_rsa -q

Even if i am using -q, still asks yes or no to override the file.

Thanks in advance

2

Answers


  1. I would suggest you to check the yes command.
    It is sending a loop of y.
    If you want to force the acceptation of the command it should work.
    But if the keygen request for an input (filename, etc.) it will also send ‘y’.

    the command would be :

    yes | ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/id_rsa -q
    
    Login or Signup to reply.
  2. i suggest using the echo command to send "yes" to the command.

    echo "yes" | ssh-keygen -t rsa -b 4096 -N '' -f ~/.ssh/id_rsa -q

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search