MilkyWiki GithubDeployKey Edit MetaEdit Search
Github Deploy Keyを使うことで、デプロイ環境から対象リポジトリのみ取得可能にすることができる。
gh cliのFine-graded tokenでも同じようなことができるが、デプロイ先環境ではsshキーを使った方が楽。
サーバーにて
$ ssh-keygen -t ed25519 -f ~/.ssh/id_github -N "" -C "$(hostname)"
$ cat ~/.ssh/id_github.pub
公開鍵をコピー
組織のSettings→Deploy keysでEnabledに設定
リポジトリのSettings→Deploy Keys→Add newで先ほどのを追加
名前はホスト名(公開鍵のコメント部分)、write accessはなし
SSHに登録
$ nano ~/.ssh/config
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_github
IdentitiesOnly yes
git cloneにどの鍵を使うかを明記する
$ git clone git@github:user/repo.git
既存のを対応させるにはこっち
$ git remote set-url origin git@github:user/repo.git
$ git pull origin main
Back Last Update: Mon, 13 Jul 2026 22:35:40 +0900