Derive SSH host alias from DNSName instead of raw HostName

Tailscale's raw HostName field is whatever the OS reports (e.g.
"Pixel 9" with a literal space for an Android device), which breaks
when written unquoted into an SSH config Host line - ssh_config treats
space-separated words as multiple patterns, not one literal name.
DNSName is already sanitized (hyphens, no spaces) for exactly this
purpose, so derive the alias from its first label instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Tommy Rantti 2026-09-26 20:32:23 +03:00
parent 0c742e6a2f
commit 20af6b67a8

View file

@ -261,7 +261,7 @@ Host $name
IdentityFile ~/.ssh/id_ed25519_${KEY_NAME}
EOF
)
done < <(echo "$status_json" | jq -r '.Peer[] | "\(.HostName) \(.DNSName | rtrimstr("."))"')
done < <(echo "$status_json" | jq -r '.Peer[] | (.DNSName | rtrimstr(".")) as $d | "\($d | split(".")[0]) \($d)"')
new_block+=$'\n'"$end"
local old_block