LoginSignup
48
49

More than 3 years have passed since last update.

GitHubで複数のアカウントを使う場合のSSHの設定

Last updated at Posted at 2015-06-06

GitHubでは、既に登録済みの公開鍵を、違うアカウントに設定することができないので、新しい公開鍵を作成してGitHubに登録し、gitコマンドでcloneやpushをする時に、新しい公開鍵のペアとなる秘密鍵を読み込む設定をする必要がある。リモートの追加の仕方を間違わなければそれほど難しくない。

1. GitHubで新規アカウントを作成する

2. 新しい公開鍵・秘密鍵を作成する

$ cd ~/.ssh
$ ssh-keygen -t rsa -C メールアドレス -f 新しい鍵のファイル名

3. .ssh/configを以下のように設定する

Host 適当に(github-新しいアカウント名とか)
  HostName github.com
  IdentityFile ~/.ssh/new_id_rsa # 新しく作成した秘密鍵を指定
  User git
  TCPKeepAlive yes
  IdentitiesOnly yes

4. 作成した公開鍵をGitHubに登録する

5. 接続できるかチェック。

ssh -T Hostに設定した名前

6. 新しく作成したリモートリポジトリをローカルに登録

$ git remote add origin git@<.ssh/configのHostNameの名前>:githubの新アカウント名/XXX.git

※ <.ssh/configのHostNameの名前>の<>は要りません。

以上。

48
49
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
48
49