諸行無常

IT色々お勉強中のブログ

複数Githubアカウントでssh接続設定(config)を使い分ける手順

cd ~/.ssh
ssh-keygen -t rsa -C {Githubメールアドレス} -f {作成する鍵の名前}
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

vim ~/.ssh/config

Host github.sub # サブアカウント
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/private  # サブアカウント用の鍵
  TCPKeepAlive yes
  IdentitiesOnly yes

↓参考

.ssh/configファイルでSSH接続を管理する - Qiita

github秘密鍵登録

pbcopy < ~/.ssh/private.pub

f:id:babababand:20190406091723p:plain
設定画面

Adding a new SSH key to your GitHub account - GitHub Help

ssh -T git@github
Hi hogehoge! You've successfully authenticated, but GitHub does not provide shell access.

subに切り替え

ssh -T git@github.sub
Hi hogehoge! You've successfully authenticated, but GitHub does not provide shell access.

subの方のローカルを変更する。直接vim .git/config変えても良い

git config --local user.name {ユーザー名}
git config --local user.email {メールアドレス}