forked from toolshed/abra
fix: attempt to include IdentityFile if available
This is part of trying to debug: coop-cloud/organising#250 And also part of: coop-cloud/docs.coopcloud.tech#27 Where I now try to specify the same logic as `ssh -i <my-key-path>` in the underlying connection logic. This should help with being more explicit about what key is being used via the SSH config file.
This commit is contained in:
@ -563,11 +563,16 @@ func GetHostConfig(hostname, username, port string) (HostConfig, error) {
|
||||
}
|
||||
|
||||
idf = ssh_config.Get(hostname, "IdentityFile")
|
||||
|
||||
hostConfig.Host = host
|
||||
if idf != "" {
|
||||
var err error
|
||||
idf, err = identityFileAbsPath(idf)
|
||||
if err != nil {
|
||||
return hostConfig, err
|
||||
}
|
||||
hostConfig.IdentityFile = idf
|
||||
}
|
||||
|
||||
hostConfig.Host = host
|
||||
hostConfig.Port = port
|
||||
hostConfig.User = username
|
||||
|
||||
@ -575,3 +580,25 @@ func GetHostConfig(hostname, username, port string) (HostConfig, error) {
|
||||
|
||||
return hostConfig, nil
|
||||
}
|
||||
|
||||
func identityFileAbsPath(relPath string) (string, error) {
|
||||
var err error
|
||||
var absPath string
|
||||
|
||||
if strings.HasPrefix(relPath, "~/") {
|
||||
systemUser, err := user.Current()
|
||||
if err != nil {
|
||||
return absPath, err
|
||||
}
|
||||
absPath = filepath.Join(systemUser.HomeDir, relPath[2:])
|
||||
} else {
|
||||
absPath, err = filepath.Abs(relPath)
|
||||
if err != nil {
|
||||
return absPath, err
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("resolved %s to %s to read the ssh identity file", relPath, absPath)
|
||||
|
||||
return absPath, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user