Skip to content

Handshake failed: ssh: unable to authenticate #69

@gopherunner

Description

@gopherunner

Hi, I'm trying to run a remote command to a host but it fails with the following error message and I can't find what is wrong:

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

Here is the code:

const (
    PKEY = "/root/.ssh/id_rsa"
)
...
output, err := utils.RunSSHCommand(user, host, PKEY, "cat /some/file")
...
func RunSSHCommand(user, addr, key, cmd string) (string, error) {
	ssh := &easyssh.MakeConfig{
		User:    user,
		Server:  addr,
		KeyPath: key,
		Port:    "22",
		Timeout: 60 * time.Second,
	}
	stdout, stderr, done, err := ssh.Run(cmd, 60*time.Second)
	if err != nil {
		color.Error.Printf("[SSH Error] Cant run remote command (%s), error msg: %s\n", cmd, err.Error())
	} else {
		if done {
			return stdout, err
		} else {
			color.Error.Printf("[SSH Error] Command error execution msg: %s\n", stderr)
		}
	}
	return "", err
}

Any ideas of what could be the problem here? I've already check that the key exists. I'm running this code from a docker container, and I pass the private key from the server running the container to the container it self on the docker-compose file like these:

...
volumes:
- /root/.ssh/id_rsa:/root/.ssh/id_rsa
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions