How can I get my own ssh fingerprint with Go?
Finger, err := ssh.**
log.Println(Finger)
// 12:f8:7e:78:61:b4:bf:e2:de:24:15:96:4e:d4:72:53
How can I get my own ssh fingerprint with Go?
Finger, err := ssh.**
log.Println(Finger)
// 12:f8:7e:78:61:b4:bf:e2:de:24:15:96:4e:d4:72:53
A key signature is is just a cryptographic hash of the unencoded key data in ssh wire format.
Here is a basic example of parsing an ssh key from the OpenSSH format public key, and getting an MD5 fingerprint:
key, err := ioutil.ReadFile("/path/to/id_rsa.pub")
if err != nil {
log.Fatal(err)
}
parts := strings.Fields(string(key))
if len(parts) < 2 {
log.Fatal("bad key")
}
k, err := base64.StdEncoding.DecodeString(parts[1])
if err != nil {
log.Fatal(err)
}
fp := md5.Sum([]byte(k))
fmt.Print("MD5:")
for i, b := range fp {
fmt.Printf("%02x", b)
if i < len(fp)-1 {
fmt.Print(":")
}
}
fmt.Println()