8

On Linux, an IPv6 address can have a scope ID at the end with a percent sign before it. For example: fe80::1%usb0. See Why is there a percent sign '%' in the IPv6 address?

I want to add such an entry to my ssh config, but if I add HostName fe80::1%usb0 to ~/.ssh/config, I get an error:

percent_expand: unknown key %u
Tor Klingberg
  • 623
  • 2
  • 8
  • 17

3 Answers3

10

You need to double the percent sign, like this:

Host vmiab
    HostName fe80::1%%usb0

ssh-config has various substitutions such as %h and %l, and if you want a literal percent sign it has to be escaped as %%.

Tor Klingberg
  • 623
  • 2
  • 8
  • 17
2

In case you are still trying to do proxy commands on the command line in zsh, here is an example of how to use it with ipv6 addresses

ssh -v -o "ProxyCommand sush -W \[%h\]:%p your_jump_server" your_user@aabb:aabb:aabb:aabb:aabb:aabb:aabb:0000

See how the h argument has now the escaped brackets but the ipv6 does not have any

Ob200
  • 21
  • 1
1

Beside the escaping of the percent sign, it can be necessary to enclose an ipv6 address into brackets [].
It's necessary when the hostname is used by a ProxyCommand.

Host vmiab
    HostName [fe80::1%%usb]
    ProxyCommand ssh my_proxy_host -W %h:%p

Or you could enclose the host [%h] in the ProxyCommand (prefered solution)

Host vmiab
    HostName fe80::1%%usb
    ProxyCommand ssh my_proxy_host -W [%h]:%p

It's better to use the brackets in the ProxyCommand, because using brackets in the hostname only works with ProxyCommand, but fails without.

jeb
  • 387
  • 2
  • 12
  • 1
    Note using brackets on the command line was rejected by OpenSSH: https://bugzilla.mindrot.org/show_bug.cgi?id=1602 – MarcH May 15 '20 at 23:02
  • How to support IPv6 in HostName? In MacOS its failing with or without bracket – Nasir Sep 08 '21 at 00:59
  • zsh:1: no matches found: [111b:c110:102:5477:0:2:0:3]:22 kex_exchange_identification: Connection closed by remote host – Nasir Sep 08 '21 at 01:19