-1

Please advice how to generate the file id_rsa.pub without answering the questions from "ssh-keygen -t rsa"

my target is to run the ssh-keygen from bash script from postgress USER, and it must run interactive , or maybe run the id_rsa.pub with different syntax ?

Example - this approach ins"t interactive :

 su - postgres -c "ssh-keygen -t rsa"
 Generating public/private rsa key pair.
 Enter file in which to save the key (/var/lib/pgsql/.ssh/id_rsa):
 Enter passphrase (empty for no passphrase):
 Enter same passphrase again:
 Your identification has been saved in /var/lib/pgsql/.ssh/id_rsa.
 Your public key has been saved in /var/lib/pgsql/.ssh/id_rsa.pub.
 The key fingerprint is:
 a5:c8:fb:ff:fa:3b:55:59:9c:90:4e:28:35:f0:46:7c 
 The key's randomart image is:
 +--[ RSA 2048]----+
 |         .++..o..|
 |         .oo.E .o|
 |          oo+   o|
 |     . . o.  . ..|
 |      o S      . |
 |       .      .  |
 |      .      .   |
 |       .    .    |
 |        ..o++o   |
 +-----------------+



 # ls
 authorized_keys  id_rsa  id_rsa.pub  known_hosts

I already try the following by EOF loop in order to answers the ssh-keygen interactive but without success

# su - postgres -c "ssh-keygen -t rsa
>
>
> <<<EOF"
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/pgsql/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
shalom
  • 451
  • 12
  • 26

3 Answers3

0

Try ssh-keygen -t rsa -f id_rsa -P ''

The -f flag will specify the file location and the -P flag will specify the passphrase (empty in this case).

0

You can specify the passphrase with the -N argument

    ssh-keygen -t rsa -N "passphrase"
-1

this is the working answer to create the public key from postgresql user

   su - postgres -c " cat /dev/zero | ssh-keygen -q -N \"\" "
shalom
  • 451
  • 12
  • 26