3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Githubアカウントを個人と会社別々で運用したい時の設定

Posted at

はじめに

私用の端末1台で会社と個人のGithubアカウントを分けなければいけない時が過去にあったので、備忘録としてこの記事を書いていきます。

注意点

  • sshでのクローンを想定しているのでhttpsでのクローンは割愛します。(というかわからん)
  • 端末でSSHについて一切設定していない場合、~/.sshディレクトリが存在しませんがそこについては別な記事で触れようと思っているので今回は割愛します。
  • あとは自己責任やで!

準備

クライアント側

SSHキーの生成

ssh-keygenコマンドを使用して、個人と会社それぞれのGithubに登録するSSHキーを生成します。

ssh-keygenコマンドの使い方はこちらの記事をいつも参考にしてます。

別々に管理したほうがセキュリティ的にも安心できるので、分けた方が良いと思いますよ!

~/.ssh/configの編集

ホスト別にSSHキーの参照先を変更しています。

この設定をすることでサブドメインでの判別が可能となり、URLで対象Githubアカウントを区別しています。

# 個人アカウント用
Host wannoko.github.com
	HostName github.com
	User git
	Port 22
	IdentityFile ~/.ssh/id_rsa
	TCPKeepAlive yes
	IdentitiesOnly yes

# 会社アカウント用(Googleにいる想定)
Host google.github.com
	HostName github.com
	User git
	Port 22
	IdentityFile ~/.ssh/google_rsa
	TCPKeepAlive yes
	IdentitiesOnly yes

Github側

SSHキーの登録

個人と会社で使用するGithubアカウントそれぞれに、生成したSSHキーを登録してください。

実際の流れ

クローンに利用するURLを書き換える

Clone with SSHからコピーしてきたURLを個人と会社別々で使用する時に書き換えます。

個人の場合

git@wannoko.github.com:{リポジトリ名}

会社の場合

git@google.github.com:{リポジトリ名}

クローンする

git cloneコマンドとかでクローンしてね!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?