I am having trouble getting go.crypto ssh client to connect

585 views
Skip to first unread message

flyfish

unread,
Mar 28, 2012, 5:24:21 PM3/28/12
to golan...@googlegroups.com
Here is example test code with server, username and password not set of course, it returns with the following error. Any help as to whats going wrong would be great.

   ERROR: "ssh: unable to authenticate, no supported methods remain"


package main

import (
"log"
)

var (
server = "server:port"
username = "username"
password = clientPassword("password")
)

// password implements the ClientPassword interface
type clientPassword string

func (p clientPassword) Password(user string) (string, error) {
        return string(p), nil
}

func main() {

log.Print("SERVER: " + server)
log.Print("USERNAME: " + username)
log.Print("PASSWORD: " + password)

_, err := password.Password(username)
if err != nil {
        log.Print("unable to retrieve password: ", err)
panic(1)
}

    config := &ssh.ClientConfig{
        User: username,
        Auth: []ssh.ClientAuth{
            ssh.ClientAuthPassword(password),
        },
}
log.Print("Length of config.Auth: ", len(config.Auth))

    c, err := ssh.Dial("tcp", server, config)
    if err != nil {
        log.Print("ERROR, unable to dial remote server: ", err)
        panic(1)
    }
    c.Close()

}

Dave Cheney

unread,
Mar 28, 2012, 5:48:51 PM3/28/12
to flyfish, golan...@googlegroups.com
I think your server does not support "password" authentication.

You can confirm this with ssh -vv and look for the supported authentication methods.

Also, log.Fatalf is probably better than panic()ing.

flyfish

unread,
Mar 28, 2012, 7:37:53 PM3/28/12
to golan...@googlegroups.com, flyfish
Aah ok, I will look into what authentications are enabled on our server. I assumed password authentication would be enabled and I bet its not. Thank you for pointing me in the right direction. Oh, and I will drop the panic for log.Fatal ;)


On Wednesday, March 28, 2012 5:48:51 PM UTC-4, Dave Cheney wrote:
I think your server does not support "password" authentication.

You can confirm this with ssh -vv and look for the supported authentication methods.

Also, log.Fatalf is probably better than panic()ing.

flyfish

unread,
Mar 29, 2012, 9:12:37 PM3/29/12
to golan...@googlegroups.com, flyfish
Its looks like our ssh server is setup to use PAM with authentication for publickey and keyboard-interactive. I have not looked into how keyboard-interactive works yet but I would imagine it is using its own tty terminal instead of stdin. 

My Xaomix

unread,
Mar 1, 2024, 9:27:03 AM3/1/24
to golang-nuts

The error message "ssh: unable to authenticate, no supported methods remain" typically indicates that the SSH client and server were unable to negotiate a mutually supported authentication method.


In your code, you're using password authentication (ssh.ClientAuthPassword), but it seems like the server you're trying to connect to may not support this authentication method.

Here are a few steps you can take to troubleshoot this issue:

  1. Check SSH Server Configuration: Make sure that the SSH server you're connecting to supports password authentication. Some servers may disable password authentication for security reasons and only allow public key authentication.

  2. Use Correct Username and Password: Double-check that the username and password you're providing are correct and valid for connecting to the SSH server.

  3. Try Public Key Authentication: If the server supports it, you may want to try using public key authentication instead of password authentication. Generate an SSH key pair (public and private key) and configure the server to accept the public key for authentication.

  4. Debug SSH Connection: Enable SSH debug logging to get more detailed information about the SSH negotiation process. You can do this by setting config.Logger to log.New(os.Stderr, "", log.LstdFlags) in your ssh.ClientConfig.

  5. Verify Network Connectivity: Ensure that there are no network issues preventing the SSH client from connecting to the server. Firewalls, network restrictions, or connectivity issues could also cause authentication failures.

Reply all
Reply to author
Forward
0 new messages