Skip to content

Commit

Permalink
Add option to add the ssh key to the ssh agent
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Nov 8, 2020
1 parent 274be7f commit da09588
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type DockerShellConfig struct {
var (
noProxy bool
sshHost bool
sshAdd bool
dockerUnset bool
defaultNoProxyGetter NoProxyGetter
)
Expand Down Expand Up @@ -236,6 +237,20 @@ var dockerEnvCmd = &cobra.Command{
}
}

if sshAdd {
klog.Infof("Adding %v", d.GetSSHKeyPath())

path, err := exec.LookPath("ssh-add")
if err != nil {
exit.Error(reason.IfSSHClient, "Error with ssh-add", err)
}

err = exec.Command(path, d.GetSSHKeyPath()).Run()
if err != nil {
exit.Error(reason.IfSSHClient, "Error with ssh-add", err)
}
}

if err := dockerSetScript(ec, os.Stdout); err != nil {
exit.Error(reason.InternalDockerScript, "Error generating set output", err)
}
Expand Down Expand Up @@ -349,6 +364,7 @@ func init() {
defaultNoProxyGetter = &EnvNoProxyGetter{}
dockerEnvCmd.Flags().BoolVar(&noProxy, "no-proxy", false, "Add machine IP to NO_PROXY environment variable")
dockerEnvCmd.Flags().BoolVar(&sshHost, "ssh-host", false, "Use SSH connection instead of HTTPS (port 2376)")
dockerEnvCmd.Flags().BoolVar(&sshAdd, "ssh-add", false, "Add SSH identity key to SSH authentication agent")
dockerEnvCmd.Flags().StringVar(&shell.ForceShell, "shell", "", "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect")
dockerEnvCmd.Flags().BoolVarP(&dockerUnset, "unset", "u", false, "Unset variables instead of setting them")
}
1 change: 1 addition & 0 deletions site/content/en/docs/commands/docker-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ minikube docker-env [flags]
-h, --help help for docker-env
--no-proxy Add machine IP to NO_PROXY environment variable
--shell string Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect
--ssh-add Add SSH identity key to SSH authentication agent
--ssh-host Use SSH connection instead of HTTPS (port 2376)
-u, --unset Unset variables instead of setting them
```
Expand Down

0 comments on commit da09588

Please sign in to comment.