LoginSignup
11
8

GitHubのアカウントを複数SSH接続する

Last updated at Posted at 2017-06-22

よく忘れていっつもググるから自分用メモ。

公開キーの確認

$ cd ~/.ssh/
$ ls

id_rsa.pub、id_rsa、id_ed25519.pub、id_ed25519があったりする。

鍵を作成する

$ ssh-keygen -t ed25519 -f [file name] -C 'mail address'
# -C は設定しなくてもOK。しなかったらマシン名が設定される
# Passphraseは必要なら入力する

公開鍵をコピー

$ pbcopy < ~/.ssh/[file name].pub

公開鍵をGitHubに登録する

にコピーした公開鍵を登録する。

Hostを指定する

$ vim ~/.ssh/config

に以下のように記載。

Host itigoppo.github.com
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/github_itigoppo_ed25519
  TCPKeepAlive yes
  IdentitiesOnly yes

接続テスト

$ ssh -T itigoppo.github.com

リポジトリにアクセスする

git@[host name]:[account name]/[repository name].git
の[host name]をconfigに設定したhostに変更する。

# 通常はこう
git@github.com:itigoppo/repository.git
↓
# 別のアカウントとしてSSH設定したやつはこう
git@itigoppo.github.com:itigoppo/repository.git
11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8