Skip to content

Commit

Permalink
feat: add ssh-agent authentication method support (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Infra-Red committed Feb 16, 2021
1 parent 76be6fd commit af50be1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tunnel := sshtunnel.NewSSHTunnel(
// Pick ONE of the following authentication methods:
sshtunnel.PrivateKeyFile("path/to/private/key.pem"), // 1. private key
ssh.Password("password"), // 2. password
sshtunnel.SSHAgent(), // 3. ssh-agent

// The destination host and port of the actual server.
"dqrsdfdssdfx.us-east-1.redshift.amazonaws.com:5439",
Expand Down
16 changes: 16 additions & 0 deletions ssh_agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sshtunnel

import (
"net"
"os"

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)

func SSHAgent() ssh.AuthMethod {
if sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil {
return ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)
}
return nil
}

0 comments on commit af50be1

Please sign in to comment.