Skip to content

Commit 4c40d10

Browse files
authored
Merge pull request #184 from ben-krieger/ignore-ssh-certs
Ignore .pub files in $HOME/.ssh without a matching private key
2 parents 5258ac0 + 6dff885 commit 4c40d10

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/sshutil/sshutil.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sshutil
33
import (
44
"errors"
55
"fmt"
6+
"io/fs"
67
"os"
78
"os/exec"
89
"os/user"
@@ -110,7 +111,7 @@ func CommonArgs(useDotSSH bool) ([]string, error) {
110111
}
111112
args := []string{"-i", privateKeyPath}
112113

113-
// Append all private keys corresponding to ~/.ssh/*.pub to keep old instances workin
114+
// Append all private keys corresponding to ~/.ssh/*.pub to keep old instances working
114115
// that had been created before lima started using an internal identity.
115116
if useDotSSH {
116117
homeDir, err := os.UserHomeDir()
@@ -127,7 +128,16 @@ func CommonArgs(useDotSSH bool) ([]string, error) {
127128
}
128129
privateKeyPath := strings.TrimSuffix(f, ".pub")
129130
_, err = os.Stat(privateKeyPath)
131+
if errors.Is(err, fs.ErrNotExist) {
132+
// Skip .pub files without a matching private key. This is reasonably common,
133+
// due to major projects like Vault recommending the ${name}-cert.pub format
134+
// for SSH certificate files.
135+
//
136+
// e.g. https://www.vaultproject.io/docs/secrets/ssh/signed-ssh-certificates
137+
continue
138+
}
130139
if err != nil {
140+
// Fail on permission-related and other path errors
131141
return nil, err
132142
}
133143
args = append(args, "-i", privateKeyPath)

0 commit comments

Comments
 (0)