GoLang ssh : Getting "Must specify HosKeyCallback" error despite setting it to nil


I am trying to connect to a remote server using GoLang. In the client configuration, apart from user and password, I set HostKeyCallback to nil so that it accepts every host

config := &ssh.ClientConfig{

        User: user,

        HostKeyCallback: nil,

        Auth: []ssh.AuthMethod{


But I keep getting this error.

Failed to dial: ssh: must specify HostKeyCallback

How do I solve this ?


The behavior of nil for HostKeyCallback was changed: https://github.com/golang/go/issues/19767

If you want to allow any host:

HostKeyCallback: ssh.InsecureIgnoreHostKey()

Answered By – ctcherry

Answer Checked By – Katrina (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.