Skip to content

Commit

Permalink
Ignore key decoding error when using agent auth sock (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
kke authored May 3, 2021
1 parent 4224870 commit 4a56ccf
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ func (c *SSH) Connect() error {
config.HostKeyCallback = trustedHostKeyCallback(c.HostKey)
}

sshAgentSock := os.Getenv("SSH_AUTH_SOCK")

if sshAgentSock != "" {
sshAgent, err := net.Dial("unix", sshAgentSock)
if err != nil {
return fmt.Errorf("cannot connect to SSH agent auth socket %s: %s", sshAgentSock, err)
}
config.Auth = append(config.Auth, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers))
}

_, err := os.Stat(c.KeyPath)
if err != nil && !c.keypathDefault {
return err
Expand All @@ -139,24 +149,14 @@ func (c *SSH) Connect() error {
return err
}
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
if err != nil && sshAgentSock == "" {
return err
}
config.Auth = append(config.Auth, ssh.PublicKeys(signer))
}

dst := fmt.Sprintf("%s:%d", c.Address, c.Port)

sshAgentSock := os.Getenv("SSH_AUTH_SOCK")

if sshAgentSock != "" {
sshAgent, err := net.Dial("unix", sshAgentSock)
if err != nil {
return fmt.Errorf("cannot connect to SSH agent auth socket %s: %s", sshAgentSock, err)
}
config.Auth = append(config.Auth, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers))
}

var client *ssh.Client

if c.Bastion == nil {
Expand Down

0 comments on commit 4a56ccf

Please sign in to comment.