In mac,I can login rain01 without password using key,In rain01 ,I can run command ssh tree01,then I logged.but using golang ssh package,I was told SSH_AUTH_SOCK
is null,and this is error msg dial unix: missing address
this is my code
func SSHClient(hostport string, username string) (*ssh.Client, error) {
sock, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
if err != nil {
logrus.Infof("error login,details: %s",err.Error())
return nil,err
}
agent := agent.NewClient(sock)
signers, err := agent.Signers()
if err != nil {
logrus.Infof("error login,details: %s",err.Error())
return nil,err
}
auths := []ssh.AuthMethod{ssh.PublicKeys(signers...)}
cfg := &ssh.ClientConfig{
User: username,
Auth: auths,
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
cfg.SetDefaults()
logrus.Infof("tcp dial to %s",hostport)
client, err := ssh.Dial("tcp", hostport, cfg)
if err != nil {
logrus.Infof("error login,details: %s",err.Error())
return nil,err
}
return client, nil
}
Now I have the var ssh_auth_sock,but there is another problem
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
and main ssh config is
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
HostbasedAuthentication no
IgnoreRhosts yes
RhostsRSAAuthentication no