Skip to content

Commit

Permalink
Merge pull request #16934 from sethrylan/fix-16933
Browse files Browse the repository at this point in the history
Add mkdir for `~/.ssh` directory.
  • Loading branch information
spowelljr authored Aug 10, 2023
2 parents 8cdc5c7 + 2587f3f commit 1c430a4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/minikube/cmd/ssh-host.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ func appendKnownHelper(nodeName string, appendKnown bool) {
if port != 22 {
host = fmt.Sprintf("[%s]:%d", addr, port)
}
knownHosts := filepath.Join(homedir.HomeDir(), ".ssh", "known_hosts")

fmt.Fprintf(os.Stderr, "Host added: %s (%s)\n", knownHosts, host)
sshDir := filepath.Join(homedir.HomeDir(), ".ssh")
err = os.MkdirAll(sshDir, os.FileMode(0700)) // drwx------, to match ssh-keygen behavior
if err != nil {
out.ErrLn("MkdirAll: %v", err)
os.Exit(1)
}

knownHosts := filepath.Join(sshDir, "known_hosts")

if sshutil.KnownHost(host, knownHosts) {
return
}
Expand All @@ -113,6 +120,8 @@ func appendKnownHelper(nodeName string, appendKnown bool) {
os.Exit(1)
}

fmt.Fprintf(os.Stderr, "Host added: %s (%s)\n", knownHosts, host)

return
}
}
Expand Down

0 comments on commit 1c430a4

Please sign in to comment.