27
26

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で会社アカウントとプライベートアカウントを使い分ける SSH編

Last updated at Posted at 2016-04-11

結構あるんじゃないでしょうか。

こちらを参考にさせて頂いたのですが、いくつかその通りいかない点があったのでまとめます。

GitHubで複数のアカウントを使う場合のSSHの設定
http://qiita.com/merrill/items/80a8d8a152e2483fa587

すでにGitHubにアカウントは存在する前提です。

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

cd ~/.ssh
ssh-keygen -t rsa -C hogehoge@gmail.com  -f id_rsa_hogehoge_github

// hogehoge@gmail.com ... githubアカウントのメールアドレス
// id_rsa_hogehoge_github ... 鍵のファイル名

以下が生成されます。

id_rsa_hogehoge_github
id_rsa_hogehoge_github.pub

公開鍵をgithubに登録する

こちらから登録
https://github.com/settings/keys

id_rsa_hogehoge_github.pubの中身をまるっと貼り付ければOK

.ssh/configの設定

.ssh/config
Host hogehoge-github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_hogehoge_github
  User git
  TCPKeepAlive yes
  IdentitiesOnly yes


# hogehoge-github.com は適当なホスト識別子

Github上でリポジトリを作成する

以下から作成
https://github.com/new

ついでに.gitignore,licenseも生成してしまうのがおすすめ。

リポジトリをcloneする

ここがはまりました

git clone git@hogehoge-github.com:hogehoge/HogeProject.git


// hogehoge-github.com ... .ssh/configで指定したホスト識別子
// hogehoge ... githubのユーザー名

hogehoge-github.comでcloneさえできれば、pushも指定したアカウントで行われます。

commit用のユーザー名、メールアドレスを変える

$ cd HogeProject
$ git config --local user.name 名前
$ git config --local user.email "メールアドレス"

とくにhttpsより難しいとは思いませんでした。
ご参考まで。

27
26
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
27
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?