Codebergのssh認証を公開鍵認証に変更する

Forgejo+αな感じのGitHub代替なCodebergにSSH公開鍵を登録してssh公開鍵認証でGitが使えるようにしてみました.

公式の手順はこちらにあります.少し気になったのが鍵生成のオプションでroundsが100もあること.手元のOpenSSH 10.0p2のssh-keygenのmanで確認すると既定値は16になっているので大分捻っています.

鍵ペアを生成したら*.pubの拡張子の付いた公開鍵*を以下のページから登録.

~/.ssh/configにCodebergの設定を書いておきます.Codebergはport 443でもssh接続okなのでここでは443を使うようにしています.
Userがみんなgitですが,鍵によりユーザを区別するようです.

$ grep -A 4 Host\ codeberg.org ~/.ssh/config
Host codeberg.org
  HostName codeberg.org
  User git
  IdentityFile ~/.ssh/id_ed25519
  Port 443

接続テストをします.

初回接続時にはホスト鍵の確認が必要です.Codebergのホスト鍵の鍵指紋は以下で確認できます.確認して入力しましょう.

$ ssh -T git@codeberg.org
The authenticity of host 'codeberg.org (2a0a:4580:103f:c0de::1)' can't be established.
ED25519 key fingerprint is SHA256:mIlxA9k46MmM6qdJOdMnAQpzGxF4WIVVL+fj+wZbw0g.
+--[ED25519 256]--+
| ++*+=.          |
|o +.+...         |
|oBo...+ o        |
|+o*o + OE        |
|o ... +.So       |
|. o .  .o.+      |
|.= o .  .+ .     |
|..+.o   ...      |
| oo     .o.      |
+----[SHA256]-----+
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? SHA256:mIlxA9k46MmM6qdJOdMnAQpzGxF4WIVVL+fj+wZbw0g
Warning: Permanently added 'codeberg.org' (ED25519) to the list of known hosts.
Connection closed by 2a0a:4580:103f:c0de::1 port 22

接続がうまく行けば自分のアカウント名や,鍵のコメントが表示されます.

$ ssh -T git@codeberg.org
Host key fingerprint is SHA256:mIlxA9k46MmM6qdJOdMnAQpzGxF4WIVVL+fj+wZbw0g
+--[ED25519 256]--+
| ++*+=.          |
|o +.+...         |
|oBo...+ o        |
|+o*o + OE        |
|o ... +.So       |
|. o .  .o.+      |
|.= o .  .+ .     |
|..+.o   ...      |
| oo     .o.      |
+----[SHA256]-----+
Enter passphrase for key '/home/matoken/.ssh/id_ed25519':
Authenticated to codeberg.org ([2a0a:4580:103f:c0de::1]:22) using "publickey".
Hi there, matoken! You've successfully authenticated with the key named matoken@l13, but Forgejo does not provide shell access.
If this is unexpected, please log in with password and setup Forgejo under another user.

ここではmatoken@l13という鍵を使い,matokenというアカウントでログインに成功しています.

Note
Codebergはport 443でもssh接続okなのですが,ここのテストは443を使うと失敗するようです.

この状態でパスワード認証を試みると失敗します.

$ ssh -T matoken@codeberg.org -o PasswordAuthentication=yes
Host key fingerprint is SHA256:mIlxA9k46MmM6qdJOdMnAQpzGxF4WIVVL+fj+wZbw0g
+--[ED25519 256]--+
| ++*+=.          |
|o +.+...         |
|oBo...+ o        |
|+o*o + OE        |
|o ... +.So       |
|. o .  .o.+      |
|.= o .  .+ .     |
|..+.o   ...      |
| oo     .o.      |
+----[SHA256]-----+
matoken@codeberg.org: Permission denied (publickey).

TOTPの設定を有効にしてこのSSH公開鍵認証を使うようにするとそこそこ安心な感じです.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)