From 2587f3ffdf8f36d6d714daa02cddcba511961d4a Mon Sep 17 00:00:00 2001 From: Seth Rylan Gainey Date: Fri, 21 Jul 2023 22:53:57 +0000 Subject: [PATCH] Add mkdir for ssh directory. --- cmd/minikube/cmd/ssh-host.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/ssh-host.go b/cmd/minikube/cmd/ssh-host.go index 44b91e3d9f58..51d408d74cff 100644 --- a/cmd/minikube/cmd/ssh-host.go +++ b/cmd/minikube/cmd/ssh-host.go @@ -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 } @@ -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 } }