Skip to content

Commit b499494

Browse files
authored
Merge pull request #165 from mook-as/ssh-no-known-hosts
SSH: Set UserKnownHostsFile to /dev/null
2 parents 663023f + 08d4bc3 commit b499494

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

pkg/hostagent/hostagent.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ func (a *HostAgent) Run(ctx context.Context) error {
174174
}
175175
stBooting := stBase
176176
a.emitEvent(ctx, hostagentapi.Event{Status: stBooting})
177-
if err := sshutil.RemoveKnownHostEntries(sshLocalPort); err != nil {
178-
a.l.WithError(err).Error("couldn't remove existing localhost host keys")
179-
return err
180-
}
181177

182178
go func() {
183179
stRunning := stBase

pkg/sshutil/sshutil.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sshutil
22

33
import (
4-
"fmt"
54
"os"
65
"os/exec"
76
"os/user"
@@ -98,25 +97,6 @@ func DefaultPubKeys(loadDotSSH bool) ([]PubKey, error) {
9897
return res, nil
9998
}
10099

101-
func RemoveKnownHostEntries(sshLocalPort int) error {
102-
homeDir, err := os.UserHomeDir()
103-
if err != nil {
104-
return err
105-
}
106-
// `ssh-keygen -R` will return a non-0 status when ~/.ssh/known_hosts doesn't exist
107-
if _, err := os.Stat(filepath.Join(homeDir, ".ssh/known_hosts")); errors.Is(err, os.ErrNotExist) {
108-
return nil
109-
}
110-
sshFixCmd := exec.Command("ssh-keygen",
111-
"-R", fmt.Sprintf("[127.0.0.1]:%d", sshLocalPort),
112-
"-R", fmt.Sprintf("[localhost]:%d", sshLocalPort),
113-
)
114-
if out, err := sshFixCmd.CombinedOutput(); err != nil {
115-
return errors.Wrapf(err, "failed to run %v: %q", sshFixCmd.Args, string(out))
116-
}
117-
return nil
118-
}
119-
120100
func CommonArgs(useDotSSH bool) ([]string, error) {
121101
configDir, err := store.LimaConfigDir()
122102
if err != nil {
@@ -155,6 +135,7 @@ func CommonArgs(useDotSSH bool) ([]string, error) {
155135

156136
args = append(args,
157137
"-o", "StrictHostKeyChecking=no",
138+
"-o", "UserKnownHostsFile=/dev/null",
158139
"-o", "NoHostAuthenticationForLocalhost=yes",
159140
"-o", "GSSAPIAuthentication=no",
160141
"-o", "PreferredAuthentications=publickey",

0 commit comments

Comments
 (0)