Skip to content
ecdsa.com
golang.org/x/crypto/ssh (Go)Go

Error message

ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

Also printed as

  • ssh: unable to authenticate, attempted methods [none], no supported methods remain

The bracketed list reflects the `Auth` methods you configured. `[none]` alone means the client had no usable method at all — typically an empty `Auth` slice or a key that failed to load.

golang.org/x/crypto/ssh (Go) — ssh.Dial / ssh.NewClientConn

What it means

The SSH transport was established (host key accepted), but every authentication method the client tried was rejected and the server offered nothing else the client could do. The list in brackets is what the Go client attempted: `none` is the initial probe every SSH client sends, `publickey` means your keys were offered and refused. This is the Go equivalent of OpenSSH's "Permission denied (publickey)".

Why it happens

How to fix it

  1. 1.

    Load the key explicitly and verify the host

    Read the private key, fail loudly if parsing fails, and use `knownhosts` for the host key instead of `ssh.InsecureIgnoreHostKey()`.

    go
    keyBytes, err := os.ReadFile(os.ExpandEnv("$HOME/.ssh/id_ed25519"))
    if err != nil {
    	return err
    }
    signer, err := ssh.ParsePrivateKey(keyBytes)
    if err != nil {
    	return err
    }
    hostKeys, err := knownhosts.New(os.ExpandEnv("$HOME/.ssh/known_hosts"))
    if err != nil {
    	return err
    }
    client, err := ssh.Dial("tcp", "server.example.com:22", &ssh.ClientConfig{
    	User:            "deploy",
    	Auth:            []ssh.AuthMethod{ssh.PublicKeys(signer)},
    	HostKeyCallback: hostKeys,
    })
  2. 2.

    Compare fingerprints and read the server log

    sshd logs why it refused a key (bad permissions on `~/.ssh`, algorithm not accepted, unknown user). The client side never learns the reason.

    bash
    ssh-keygen -lf ~/.ssh/id_ed25519.pub                 # fingerprint of the key the program uses
    ssh deploy@server.example.com 'ssh-keygen -lf ~/.ssh/authorized_keys'
    sudo journalctl -u ssh -n 20                         # sshd's reason (modes, algorithms, user)

Related errors

Browse the full signature error database