mirror of
https://github.com/containers/podman.git
synced 2025-10-18 19:53:58 +08:00
ssh_config: allow IdentityFile file with tilde
The ssh_config can contain a path with ~/ to refer to the home dir like done on shells. Handle that special case and resolve the path correctly so it can be used. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -205,10 +206,15 @@ func sshClient(_url *url.URL, uri string, identity string, machine bool) (Connec
|
|||||||
|
|
||||||
if identity == "" {
|
if identity == "" {
|
||||||
if val := cfg.Get(alias, "IdentityFile"); val != "" {
|
if val := cfg.Get(alias, "IdentityFile"); val != "" {
|
||||||
if val != ssh_config.Default("IdentityFile") {
|
|
||||||
identity = strings.Trim(val, "\"")
|
identity = strings.Trim(val, "\"")
|
||||||
found = true
|
if strings.HasPrefix(identity, "~/") {
|
||||||
|
homedir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return connection, fmt.Errorf("failed to find home dir: %w", err)
|
||||||
}
|
}
|
||||||
|
identity = filepath.Join(homedir, identity[2:])
|
||||||
|
}
|
||||||
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user