diff --git a/pkg/ssh/ssh.go b/pkg/ssh/ssh.go index 9865390d..49ceb24f 100644 --- a/pkg/ssh/ssh.go +++ b/pkg/ssh/ssh.go @@ -475,11 +475,10 @@ func GetContextConnDetails(serverName string) (*dockerSSHPkg.Spec, error) { func GetHostConfig(hostname, username, port string) (HostConfig, error) { var hostConfig HostConfig - var host, idf string - - if host = ssh_config.Get(hostname, "Hostname"); host == "" { - logrus.Debugf("no hostname found in SSH config, assuming %s", hostname) - host = hostname + if hostname == "" { + if hostname = ssh_config.Get(hostname, "Hostname"); hostname == "" { + logrus.Debugf("no hostname found in SSH config, assuming %s", hostname) + } } if username == "" { @@ -500,17 +499,19 @@ func GetHostConfig(hostname, username, port string) (HostConfig, error) { } } - idf = ssh_config.Get(hostname, "IdentityFile") - if idf != "" { + if idf := ssh_config.Get(hostname, "IdentityFile"); idf != "" && idf != "~/.ssh/identity" { var err error idf, err = identityFileAbsPath(idf) if err != nil { return hostConfig, err } hostConfig.IdentityFile = idf + } else { + logrus.Debugf("no identity file found in SSH config for %s", hostname) + hostConfig.IdentityFile = "" } - hostConfig.Host = host + hostConfig.Host = hostname hostConfig.Port = port hostConfig.User = username