.ssh/config ファイルのオプション設定が理解できていなかったので、整理しておく。
同一ホスト名に対して、別々のアカウントでそれぞれGit接続したい場合の対処方法も載せた。
実行環境
- macOS Catalina 10.15.6
.ssh/config ファイルについて
私は、いつもこんな感じで書いている。
これで、問題なく使えているが、PreferredAuthenticationsはなんで必要なの?って聞かれたら答えられなかったので、それぞれの項目の意味を表に整理した。
Host bitbucket.org
User git
HostName bitbucket.org
IdentityFile ~/.ssh/danroo_rsa
PreferredAuthentications publickey
UseKeychain yes
AddKeysToAgent yes
IdentitiesOnly yes
設定名称 | 用途・説明 |
---|---|
Host | ホスト名(Mac上で名前解決できればなんでも良い) |
User | ログインユーザ名 |
HostName | ホストのアドレスまたはIPアドレス |
Port | ポート番号 |
IdentityFile | 秘密鍵のパス |
PreferredAuthentications | 認証方法を指定 publickey: 公開鍵認証 keyboard-interactive: キーボードインタラクティブ認証 password: パスワード認証 gssapi-with-mic: api認証(未調査) hostbased: ホストベース(未調査) |
UseKeychain | MacOSに保存されたパスフレーズを参照するかどうか yes: 参照する no: 毎回パスフレーズを入力する |
AddKeysToAgent | パスフレーズをMacOSのキーチェーンアクセスに保存するかどうか yes: 保存する no: 保存しない |
IdentitiesOnly | IdentityFileで認証するかどうか yes: はい no: いいえ |
TCPKeepAlive | 接続状態を継続するかどうか yes: 継続する no: 継続しない |
ServerAliveInterval | 一定期間サーバからデータが送られてこないときに、タイムアウトする秒数 |
同一ホスト名に対して、別々のアカウントでそれぞれGit接続したい場合
二つのリポジトリがあり、
ホスト名は両方「bitbucket.org」だけど、アカウントが別になっているケース。
やり方としては、Hostの記載とGitのリモート指定を合わせることで、
両方のリポジトリへの接続を可能になった。
.ssh/config は、Hostの名称を区別させる。
$ vi ~/.ssh/config
Host bitbucket.org
User git
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket_test_rsa
Host nonochi123.bitbucket.org
User git
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket_nonoichi123_rsa
ローカルリポジトリの.git/configを開いて、remote設定を.ssh/configのHostの名称に変更する
$ vi .git/config
[remote "origin"]
url = ssh://git@nonochi123.bitbucket.org/nonoichi123/www.danroo.com.git
pushurl = ssh://git@nonochi123.bitbucket.org/nonoichi123/www.danroo.com.git
参考リンク
- ssh_config(5): OpenSSH SSH client config files – Linux man page
https://linux.die.net/man/5/ssh_config
コメントを書く