From dddf84d92b505428fabd5e05deaf5d601a3adbcc Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Fri, 24 Dec 2021 15:34:25 +0100 Subject: [PATCH] fix: avoid default value for idf We could default to ~/.ssh/id_rsa but if that doesn't exist, then we'll just be confusing people in the logs. Best is to just rely on the ssh-agent which overrides this anyway. We will document this. See https://git.coopcloud.tech/coop-cloud/organising/issues/277 --- pkg/ssh/ssh.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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