How can I add an IPv6 address with a scope ID to the ssh config file?

6

3

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

Posted 2015-08-05T15:54:59.603

Reputation: 463

Answers

8

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

Posted 2015-08-05T15:54:59.603

Reputation: 463

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

Posted 2015-08-05T15:54:59.603

Reputation: 216