diff --git a/containers/types.go b/containers/types.go index 560a1a5..e9159be 100644 --- a/containers/types.go +++ b/containers/types.go @@ -292,14 +292,26 @@ func (c *Container) GetHostKey() (string, error) { return "", err } + // Loop over lines and search for localhost ssh + line := "" if hostKeyRaw != nil { - hostKeyRawString := strings.TrimSpace(string(*hostKeyRaw)) - parts := strings.SplitN(hostKeyRawString, " ", 2) - if len(parts) > 1 { - return parts[1], nil + for _, line = range strings.Split(string(*hostKeyRaw), "\n") { + if strings.HasPrefix(line, "localhost ssh") { + line = strings.TrimSpace(line) + break + } } } + if line == "" { + return "", errors.New("key not found") + } + + parts := strings.SplitN(line, " ", 2) + if len(parts) > 1 { + return parts[1], nil + } + return "", errors.New("key not found") }