Skip to content

feat(shell): allow configuring ssh alias #1132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2022
Merged

feat(shell): allow configuring ssh alias #1132

merged 1 commit into from
Nov 4, 2022

Conversation

antoineco
Copy link
Contributor

@antoineco antoineco commented Oct 25, 2022

If the SSH environment variable is set, limactl shell will consider this as an alias for the ssh command to execute, instead of looking up a ssh executable in the PATH.

The provided command can be anything that is CLI-compatible with the OpenSSH client, such as a shell script that passes all provided arguments to ssh.

Closes #1131


Demo

export SSH='kitty +kitten ssh'
go run ./cmd/limactl/ shell my-vm
$ ps ww
16004 s000  S+     0:00.07 kitty +kitten ssh -F /dev/null -o IdentityFile="/Users/acotten/.lima/_config/user" -o IdentityFile="/Users/acotten/.ssh/id_ed25519" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o NoHostAuthenticationForLocalhost=yes -o GSSAPIAuthentication=no -o PreferredAuthentications=publickey -o Compression=no -o BatchMode=yes -o IdentitiesOnly=yes -o Ciphers="^[email protected],[email protected]" -o User=acotten -o ControlMaster=auto -o ControlPath="/Users/acotten/.lima/my-vm/ssh.sock" -o ControlPersist=5m -t -o SendEnv="COLORTERM" -q -p 51808 127.0.0.1 -- cd /Users/acotten/git/antoineco/lima-vm-lima || cd /Users/acotten ; exec "$SHELL" --login

var arg0Args []string

if sshShell := os.Getenv(envShellSSH); sshShell != "" {
sshShellFields := strings.Fields(sshShell)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this split the string using shell quoting semantics?

I don't know if there is a recommended function for it, but a quick search found

This seems to do what I would expect, but I haven't actually looked at the implementation:

shlex.Split("one \"two three\" four") -> []string{"one", "two three", "four"}

Copy link
Contributor Author

@antoineco antoineco Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had simple use cases in mind, but you're raising an excellent point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b6645274..5ca81769.

PTAL

@antoineco

This comment was marked as outdated.

@antoineco antoineco closed this Oct 25, 2022
@antoineco antoineco deleted the feat/shell-ssh-cmd branch October 25, 2022 16:16
@antoineco antoineco restored the feat/shell-ssh-cmd branch October 28, 2022 17:11
@antoineco antoineco reopened this Oct 28, 2022
@antoineco antoineco closed this Oct 28, 2022
@antoineco antoineco deleted the feat/shell-ssh-cmd branch October 28, 2022 18:46
@antoineco antoineco restored the feat/shell-ssh-cmd branch October 28, 2022 18:47
@antoineco antoineco reopened this Oct 28, 2022
@antoineco antoineco requested review from jandubois and AkihiroSuda and removed request for jandubois and AkihiroSuda October 28, 2022 19:10
AkihiroSuda
AkihiroSuda previously approved these changes Nov 2, 2022
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda added this to the v0.14 (tentative) milestone Nov 2, 2022
If the LIMASHELL_SSH environment variable is set, 'limactl shell' will
consider this as an alias for the 'ssh' command to execute, instead of
looking up a 'ssh' executable in the PATH.

The provided command can be anything that is CLI-compatible with the
OpenSSH client, such as a shell script that passes all provided
arguments to 'ssh'.

Signed-off-by: Antoine Cotten <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda requested a review from jandubois November 3, 2022 20:21
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM and works as expected.

@jandubois jandubois merged commit 49ee9b7 into lima-vm:master Nov 4, 2022
@antoineco antoineco deleted the feat/shell-ssh-cmd branch November 4, 2022 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

limactl shell does not consider potential ssh shell aliases
3 participants