@@ -12,14 +12,22 @@ import (
12
12
"github.com/lima-vm/lima/pkg/sshutil"
13
13
"github.com/lima-vm/lima/pkg/store"
14
14
"github.com/mattn/go-isatty"
15
+ "github.com/mattn/go-shellwords"
15
16
"github.com/sirupsen/logrus"
16
17
"github.com/spf13/cobra"
17
18
)
18
19
20
+ // Environment variable that allows configuring the command (alias) to execute
21
+ // in place of the 'ssh' executable.
22
+ const envShellSSH = "SSH"
23
+
19
24
var shellHelp = `Execute shell in Lima
20
25
21
26
lima command is provided as an alias for limactl shell $LIMA_INSTANCE. $LIMA_INSTANCE defaults to "` + DefaultInstanceName + `".
22
27
28
+ By default, the first 'ssh' executable found in the host's PATH is used to connect to the Lima instance.
29
+ A custom ssh alias can be used instead by setting the $` + envShellSSH + ` environment variable.
30
+
23
31
Hint: try --debug to show the detailed logs, if it seems hanging (mostly due to some SSH issue).
24
32
`
25
33
@@ -126,9 +134,28 @@ func shellAction(cmd *cobra.Command, args []string) error {
126
134
)
127
135
}
128
136
129
- arg0 , err := exec .LookPath ("ssh" )
130
- if err != nil {
131
- return err
137
+ var arg0 string
138
+ var arg0Args []string
139
+
140
+ if sshShell := os .Getenv (envShellSSH ); sshShell != "" {
141
+ sshShellFields , err := shellwords .Parse (sshShell )
142
+ switch {
143
+ case err != nil :
144
+ logrus .WithError (err ).Warnf ("Failed to split %s variable into shell tokens. " +
145
+ "Falling back to 'ssh' command" , envShellSSH )
146
+ case len (sshShellFields ) > 0 :
147
+ arg0 = sshShellFields [0 ]
148
+ if len (sshShellFields ) > 1 {
149
+ arg0Args = sshShellFields [1 :]
150
+ }
151
+ }
152
+ }
153
+
154
+ if arg0 == "" {
155
+ arg0 , err = exec .LookPath ("ssh" )
156
+ if err != nil {
157
+ return err
158
+ }
132
159
}
133
160
134
161
sshOpts , err := sshutil .SSHOpts (inst .Dir , * y .SSH .LoadDotSSHPubKeys , * y .SSH .ForwardAgent , * y .SSH .ForwardX11 , * y .SSH .ForwardX11Trusted )
@@ -151,7 +178,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
151
178
"--" ,
152
179
script ,
153
180
}... )
154
- sshCmd := exec .Command (arg0 , sshArgs ... )
181
+ sshCmd := exec .Command (arg0 , append ( arg0Args , sshArgs ... ) ... )
155
182
sshCmd .Stdin = os .Stdin
156
183
sshCmd .Stdout = os .Stdout
157
184
sshCmd .Stderr = os .Stderr
0 commit comments