LoginSignup
1
1

More than 5 years have passed since last update.

GitHubで複数のアカウント使い分けたい時のやり方

Last updated at Posted at 2019-02-11

個人用、会社用とGitHubのアカウントが複数ある人向け。昔設定したのにもう忘れてしまったのでメモ。

現状確認

shuka@saito ~ $ cd ~/.ssh/
shuka@saito ~/.ssh $ ls
id_rsa.pub id_rsa

秘密鍵・公開鍵が1ペアで存在していますね。

もう1つの鍵を生成

既にある鍵のペアを1つのアカウントに利用するとして、もう1つのアカウントを紐付けるための秘密鍵・公開鍵を生成します。

shuka@saito ~/.ssh $ ssh-keygen -t rsa -C "cancolle_sub@pfcolle.com" -f github_sub_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in github_sub_id_rsa.
Your public key has been saved in github_sub_id_rsa.pub.

あとはsshのconfigを編集して終わり

shuka@saito ~/.ssh $ vim config

~/.ssh/configの内容(例)

# github_office
Host github-saito
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/id_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

#github_private
Host github-shuka
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/github_sub_id_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

このあと、ディレクトリ毎にGitの情報を変更したい場合(例えば、会社用は本名、プライベート用は個人みたいな)は下記の記事をご参照ください。

Gitでの名前を使いわけたい人向けメモ

参考文献

【メモ】githubの複数アカウントにSSH接続するための設定手順 | DevelopersIO

1
1
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
1
1