title: How can I obtain the known_hosts formatted public key value for ec2 instance ssh-key?
body: <p>AWS outputs this key line <code>2048 SHA256:2p2o3eIz/XxxX6IIegXx5FkHo3Lap7xR+Ue2qJ0zV4w root@ip-****** (RSA)</code> to the system log. How can I replicate this format for the ssh-rsa key from the command line? I was scraping the logs until I realized that you can't rely on ec2's console-log fetching command because it's buffered and only stores a small amount of the output.</p>
  
  <p>To clarify the ssh-key file in question is a PEM style file with the beginning and ending tags for a base64 encoded <code>----RSA PRIVATE KEY----</code></p>
  
  <p>If it's helpful to know the ssh-rsa line value for the public key is base64 encoded.</p>
  
  <p>I've tried...</p>
  
  <pre><code>sudo ssh-keygen -E md5 -lf /etc/ssh/ssh_host_rsa_key
  2048 MD5:10:b6:fd:21:fb:f4:ca:6b:ef:15:50:15:af:8b:5a:5d root@ip-****** (RSA)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>sudo ssh-keygen -lf /etc/ssh/ssh_host_rsa_key
  2048 SHA256:2p2o3eIz/XxxX6IIegXx5FkHo3Lap7xR+Ue2qJ0zV4w root@ip-****** (RSA)
  </code></pre>
  
  <p>But neither produce output looking </p>
  
  <pre><code>-----BEGIN SSH HOST KEY KEYS-----
  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7+hIGwj+cfT6tLdaVuUewnY/NwoQUdAaLw30auAHQS1B/HAEEJ+f+iLjC7JM2IV00Pgbt1trttRmaApghwkB75h0NXArxrfcHTKKV2FO0d8slO9HwDUMbLOEN+L5H0/T0Xtq9u1vnOz2LyMb5KeIywa0HXZ6bGqt1rYCV3Qi369+FUrtTFw8jo8Y21LmqHVltd/d7Kv40Hb3jzqAOCh3jtZ3bilenMA9pAtXM+XJP54oS6z0NutDJLU2n1DVg2q+5wwjJJqljgYg98t5Xj8VmGlWrtam6FMcaSJ77UwMyxLsSe/Ow7DYGAMrd6PLY5RA1stj4W0WYeB8IOSgyGWPf root@ip-******
  -----END SSH HOST KEY KEYS-----
  </code></pre>