Skip to content

Commit

Permalink
Merge pull request #4 from revengel/release-0.1.4
Browse files Browse the repository at this point in the history
show public ssh key comment
  • Loading branch information
revengel authored Mar 16, 2023
2 parents 1ff65c4 + e5b3017 commit fb479d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
17 changes: 16 additions & 1 deletion ssh-add.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"errors"
"fmt"
"path/filepath"
Expand Down Expand Up @@ -428,8 +429,22 @@ func (s *gc) ShowSSHPublicKey(c *cli.Context) error {
return err
}

pubKey = bytes.SplitN(pubKey, []byte{'\n'}, 2)[0]
var pubKeySpaceParts = bytes.SplitN(pubKey, []byte{' '}, 3)
if len(pubKeySpaceParts) == 3 && bytes.Equal(pubKeySpaceParts[2], []byte("noname")) {
pubKeySpaceParts = pubKeySpaceParts[0:2]
}

if len(pubKeySpaceParts) < 3 {
var comment = getSSHKeyComment(s.key)
pubKeySpaceParts = append(pubKeySpaceParts, []byte(comment))
pubKey = bytes.Join(pubKeySpaceParts, []byte{' '})
}

var pubKeyStr = string(pubKey)

if !clip {
fmt.Println(string(pubKey))
fmt.Println(pubKeyStr)
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions ssh-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"net"
"os"

Expand Down Expand Up @@ -48,7 +47,7 @@ func (sa *sshAgent) add(privateKeyB []byte, password, comment string, lifetime u
key := agent.AddedKey{
PrivateKey: privateKey,
LifetimeSecs: lifetime,
Comment: fmt.Sprintf("%s: %s", appName, comment),
Comment: getSSHKeyComment(comment),
}
err = sa.agent.Add(key)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ func askForConfirmation(s string, ss ...any) bool {
panic(err)
}
}

func getSSHKeyComment(key string) string {
return fmt.Sprintf("%s:%s", "gssh", key)
}

0 comments on commit fb479d0

Please sign in to comment.