Skip to content

Commit 8b809f8

Browse files
committed
get: Actually only delete selected keys from the agent
`ssh-add -D` deletes *all* keys, which clearly was not intended. Also avoid calling `ssh-add -d -` at all if the set of keys to remove is empty.
1 parent 2331f93 commit 8b809f8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cmd/get.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,14 @@ var getCmd = &cobra.Command{
126126
remove.Write([]byte("\n"))
127127
}
128128
}
129-
c = exec.Command("ssh-add", "-D")
130-
c.Stdin = &remove
131-
if err := c.Run(); err != nil {
132-
return fmt.Errorf("could not remove old authentication keys from the agent: %w", err)
129+
if remove.Len() > 0 {
130+
c = exec.Command("ssh-add", "-d", "-")
131+
c.Stdin = bytes.NewReader(remove.Bytes())
132+
c.Stdout = os.Stdout
133+
c.Stderr = os.Stderr
134+
if err := c.Run(); err != nil {
135+
return fmt.Errorf("could not remove old authentication keys from the agent: %w", err)
136+
}
133137
}
134138

135139
c = exec.Command("ssh-add", privKeyPath)

0 commit comments

Comments
 (0)