Skip to content

Instantly share code, notes, and snippets.

@alexpearce
Created February 28, 2023 10:03
Show Gist options
  • Save alexpearce/41f3533b8acb9f6362db37ee5b103c2b to your computer and use it in GitHub Desktop.
Save alexpearce/41f3533b8acb9f6362db37ee5b103c2b to your computer and use it in GitHub Desktop.
function tssh --description="SSH to a machine using its Tailscale IP." --argument-names=target_host
# Find the `tailscale` executable
set cmd '/Applications/Tailscale.app/Contents/MacOS/Tailscale'
if not test -x $cmd
set cmd (which tailscale)
if test $status != 0
set_color red
printf "ERROR "
set_color normal
echo "Could not find Tailscale binary" >&2
return 1
end
end
# Resolve the hostname to a Tailscale IP
set host_ip ($cmd ip -4 $target_host 2>/dev/null)
if test $status != 0
set_color red
printf "ERROR "
set_color normal
echo "Failed to resolve Tailscale IP for host '$target_host'" >&2
return 1
end
# TODO should all the arguments `ssh` does, including username overriding.
ssh ubuntu@$host_ip
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment