Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Last active March 18, 2025 03:53
Show Gist options
  • Save yano3nora/7d05fc3a85778ef8c37d8584a07a5e6c to your computer and use it in GitHub Desktop.
Save yano3nora/7d05fc3a85778ef8c37d8584a07a5e6c to your computer and use it in GitHub Desktop.
deploy-keys

Overview

https://docs.github.com/ja/authentication/connecting-to-github-with-ssh/managing-deploy-keys

  • 単一 repo の read only 権限だけをもたせた ssh key 登録ができるやつ
  • github repo の settings から deploy keys の登録設定ができる
  • ci の組み込みから、本番 ec2 に ssh で入って git で deploy するようなレガシー環境に
# ec2 内などで鍵作成
$ ssh-keygen -t ecdsa -b 521 -f ~/.ssh/deploy_key -N ""

# 鍵の内容をコピって github repo の settings > deploy keys へ登録
$ cat ~/.ssh/deploy_key.pub

# たとえば repo の remote 向き先変更して ↑ repo に向けるとか
$ git remote set-url origin [email protected]:new-repo.git

# git v2.3 以降なら GIT_SSH_COMMAND 環境変数で
# 「git 操作時どの ssh 鍵使うか」指定可能なので、毎回 export して操作する
$ export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key"

# 疎通確認
$ git fetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment