Skip to content

Instantly share code, notes, and snippets.

@eikenb
Created September 14, 2018 02:55
Show Gist options
  • Save eikenb/0a5831a6555d762f06b6b49676b9c48e to your computer and use it in GitHub Desktop.
Save eikenb/0a5831a6555d762f06b6b49676b9c48e to your computer and use it in GitHub Desktop.
ssh client key connect
func keyConfig() ssh.ClientConfig {
PORT = "22"
sshagent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
if err != nil {
panic(err)
}
signer := ssh.PublicKeysCallback(agent.NewClient(sshagent).Signers)
sshConfig := ssh.ClientConfig{
User: os.ExpandEnv("$USER"),
Auth: []ssh.AuthMethod{signer},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
sshConfig.SetDefaults()
return sshConfig
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment