iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
😲

Why does GitHub use the 'git' user for SSH public key authentication?

に公開2件

If you think "That's not right!" or have any other feedback, please let me know in the comments.

TL;DR

Probably, GitHub identifies the user by matching the public key sent during the SSH process.

Normal (?) SSH

When you want to connect to a host as a user named user using public key authentication, you would first register your public key to the host using something like ssh-copy-id and then run:

$ ssh user@host

You probably do this when SSHing into a server.

SSH to GitHub

SSH to GitHub is a bit different. You use the user git.
(I'll skip the detailed explanation.)

Yet, you can SSH just by registering your public key to your GitHub account.

$ ssh -T git@github.com
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

Why is this?
When you specify a username to SSH, the username is known. But if every user connects via SSH as git, wouldn't it be impossible to identify the specific user?

Got information on Twitter

https://twitter.com/hase_cafesalad/status/1490201463582179329

To solve that mystery, we headed to RFC4252

Private keys are often stored in an encrypted form at the client
host, and the user must supply a passphrase before the signature can
be generated. Even if they are not, the signing operation involves
some expensive computation. To avoid unnecessary processing and user
interaction, the following message is provided for querying whether
authentication using the "publickey" method would be acceptable.

byte SSH_MSG_USERAUTH_REQUEST
string user name in ISO-10646 UTF-8 encoding [RFC3629]
string service name in US-ASCII
string "publickey"
boolean FALSE
string public key algorithm name
string public key blob

Below is the translation by DeepL (referring to the Japanese translation in the original post):

Private keys are often stored in an encrypted form at the client host, and the user must supply a passphrase before the signature can be generated. Even if they are not, the signing operation involves some expensive computation. To avoid unnecessary processing and user interaction, the following message is provided for querying whether authentication using the "publickey" method would be acceptable.

To paraphrase, it seems to mean something like: "In public key authentication, a signature is sent. The signature includes the following information."
It says string public key blob.

In other words, it suggests that GitHub uses the public key included in the SSH signature to cross-reference it with the public keys registered to users and identifies who is connecting.

I see.

While I don't know the actual implementation of GitHub's SSH daemon, it seems like a plausible theory.
If anyone knows more, please let me know.

References

Discussion

angel_p_57angel_p_57

つまり、 GitHub は SSH の署名に含まれている公開鍵を使ってユーザに登録されている公開鍵と突合し、ユーザを特定しているのではないかということです。

ユーザ名ではなく公開鍵で利用者の区別をつけるというのはそれ以外考えられないところですが、「公開鍵で区別」それ自身、特に珍しいことではありません。( もちろんSSHサーバは「利用者が何の鍵を使って認証してきてるか」を、プロトコル的に把握可能です )
一般によく使われるOpenSSHのsshdにも、「同一ユーザで複数の公開鍵をauthorized_keysに登録しておき、公開鍵毎に使えるコマンドやアクセス元として許可するアドレス等を変える」という機能があります。
※「公開鍵毎に~」の機能については、例えば「何気に便利に使えるかもしれない authorized_keys のオプション」という記事でも解説があります。

「なぜユーザ名を区別しないのか」については、以下のtweetで述べた理由だろうと思います。
https://twitter.com/angel_p_57/status/1490195138509152256

1