結論
まず、macOS と Linux で対応が少し異なる。
macOS の場合
~/.ssh/config
への記述内容として、AddKeysToAgent yes
という行と、UseKeychain yes
という行を含める。
Host github.com HostName github.com Port 22 User git IdentityFile ~/.ssh/github_secret_key AddKeysToAgent yes UseKeychain yes
Linux の場合
~/.ssh/config
への記述内容として、UseKeychain yes
を記入してはいけない*1。それ以外は macOS の場合と同じである。
Host github.com HostName github.com Port 22 User git IdentityFile ~/.ssh/github_secret_key AddKeysToAgent yes
あとは
上述の各設定が済めば、リポジトリ内の .git/config
における [remote "origin"]
のアドレスの設定を SSH にすれば OK。
[core] (省略) [remote "origin"] url = git@github.com:your_name/your_repository.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] (省略)
最初に git clone
をする際に、SSH で git clone
をすれば、[remote "origin"]
のアドレスは SSH になっている*2。
あやふやな情報
macOS だと SSH でなくてもパスが聞かれなかったような記憶がある*3。