Skip to content

Instantly share code, notes, and snippets.

View LucaIcaro's full-sized avatar

Luca Bevilacqua LucaIcaro

  • Wayve
  • London
  • 17:33 (UTC)
View GitHub Profile
@LucaIcaro
LucaIcaro / GenerateED25519SSHKeys.go
Created May 14, 2024 14:48
Generate ED25519 openssh-compatible ssh key pair. The output is ready to be used in an authorized_host file and in a private ssh key file.
// GenerateSSHKeys generates a private and public ssh key pair with ed25519 algorithm
// and returns the encoded strings
func GenerateED25519SSHKeys() (string, string, error) {
// If rand is nil, crypto/rand.Reader will be used
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
p, err := ssh.MarshalPrivateKey(crypto.PrivateKey(priv), "")
if err != nil {