title: Generate Private key with OpenSSL and Public key ssh-keygen for SSH
body: <p>I am trying to generate a secure private and public key with openssl for use with my cloud hosting provider but when I did that the public key output from openssl was not recognized.</p>
  
  <pre><code>$ openssl genrsa -out private.pem -passout file:password.txt  2048
  </code></pre>
  
  <p>After Generating RSA private key, 2048 bit long modulus, then</p>
  
  <pre><code>$ openssl rsa -in private.pem -passin file:password.txt   -pubout -out public.pem
  </code></pre>
  
  <p>It wrote the RSA public key.  The output is something like this:</p>
  
  <pre><code>-----BEGIN PUBLIC KEY-----
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuefPvX5Bih6GYbr1eTNf
  Fa++DvhHg4nxcXZAor7gNEM1+XPY2wxG2r2g/Jub6OWHd8GDAf6SBCCld+alC9WS
  KnAd2qz34yBzG4pJ5/tLux1yX5k45BPTcTHfZGmFlAxsSNTZVh5Zh9KYUpsklKOW
  2Pb5gwlMvweIoqf0lqrNqX8agDWzAn4bRbW8ZeNKUuNuccx4PlFwMg4lEcPypcCL
  HPAHGiQTR1xZ/jlohFMIH1cGCBVC4kuaEtUi3Qer9wzuvh376RQPnKD0jJgraiDM
  pSrdMeH+0eJfqckM8pJ99F/kfKWcGtk6l1AJX511xsPLDTHxaP/ry8zlaAJ1vH9o
  3wIDAQAB
  -----END PUBLIC KEY-----
  </code></pre>
  
  <p>Which is the standard format  and it works great for other use but All cloud and hosting providers need something like this for public key:</p>
  
  <pre><code>ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==
  </code></pre>
  
  <p>That is the only valid format they recognize.</p>
  
  <p>I know ssh-keygen can do all that easily but I am using the currently latest openssl version 1.0.2h with security fix for some vulnerabilities pointed out by Google and Red Hat employees. </p>
  
  <p>So how do I get the ssh-keygen public key format using my key generated from openssl? </p>