4

I'm seeing in the ssh_config man page and on the openssh website that I should be able to use a %n token when locating the identity file for a given host entry.

percent_expand tokens used by OpenSSH's ssh(1) and sshd(8)

GitHub allows using ssh tokens as deploy tokens but prevents you from using a token more than once on multiple repositories. So I wanted to use globbing to create a single profile regardless of how many individual project keys I had to create:

host github-*      
    Hostname github.com
    User git
    IdentityFile %d/.ssh/github/%n
    IdentitiesOnly yes

Then I put a github-MyPackage public/private key pair under the ~/.ssh/github/ directory.

It finds the globbed profile and the %d works fine but if I try to do a git clone with the %n to find the Identity file name from the original command-line specified host-alias:

> git clone github-MyPackage:/myorganization/MyPackage.git

Cloning into 'MyPackage'...
percent_expand: unknown key %n
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This is not simply how git accesses it as it also fails with just a simple ssh command:

> ssh github-MyPackage
percent_expand: unknown key %n

I tried googling but didn't find anything on %n. Is this not fully implemented or is there something I'm doing wrong?

2
  • 2
    IIRC not all tokens are accepted by every keyword; my ssh_config man page says "IdentityAgent and IdentityFile accept the tokens %%, %d, %h, %l, %r, and %u." Feb 18, 2021 at 19:48
  • yeah, that link I included seems to suggest it should work on a IdentifyFile line so I was hoping I could use it there.
    – Scott
    Feb 19, 2021 at 20:53

1 Answer 1

0

Probably your ssh version is to old, you could check with ssh -V.

OpenSSH_7.9p1 supports the %n only for some keywords (from the local installed man page):

Match exec
ControlPath
LocalCommand
RemoteCommand

I can't tell which specific version adds this token to IdentityFile, but it works with OpenSSH_8.9p1 for more keywords:

CertificateFile
ControlPath
IdentityAgent
IdentityFile
LocalForward
Match exec
RemoteCommand
RemoteForward
UserKnownHostsFile
ProxyCommand
3
  • that could be the case as some of these systems are on old ubuntu releases and in the process of being upgraded/replaced. But if %n is in the man page, but doesn't work in the program itself.....
    – Scott
    Jan 19, 2023 at 16:08
  • @Scott It's in the manual, but not for your keyword (IdentityFile)
    – jeb
    Jan 19, 2023 at 17:58
  • that makes sense. i think I found the suggestion itself online, saw support for it in the man page, but it wasn't clear it wasn't enabled in the idenity option.
    – Scott
    Jan 23, 2023 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .