すでに使っているGithubアカウントとは別のアカウントを作りたくて、その手順を調べた
公開鍵の作成
まずは公開鍵を生成する
~/.ssh に移動しておき、ssh-keygen -t rsaで鍵を作る
途中にid_rsaの名前を聞かれるので id_sub_rsa と入れる
$ cd ~/.ssh $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/(username)/.ssh/id_rsa):id_sub_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again:
公開鍵をクリップボードにコピー
$ pbcopy < ~/.ssh/id_sub_rsa.pub
Githubのsettings > ssh に移動して貼り付け(名前は認証名がわかればなんでもいい)
アカウントが複数あるので ~/.ssh/config ファイルを作成し、以下のように記載する
Host github.com # メインアカウント HostName github.com User git Port 22 IdentityFile ~/.ssh/id_rsa # 元々あったメインアカウント用の鍵 TCPKeepAlive yes IdentitiesOnly yes Host github.com.sub # もう一つのアカウント HostName github.com User git Port 22 IdentityFile ~/.ssh/id_sub_rsa # もう一つのアカウントの鍵 TCPKeepAlive yes IdentitiesOnly yes
接続を確認する
$ ssh -T git@github.com Hi uga! You've successfully authenticated, but GitHub does not provide shell access. $ ssh -T git@github.com.sub Hi uga2! You've successfully authenticated, but GitHub does not provide shell access.
sshでクローンする
$ git clone git@github.com.sub:xxxxx/yyyyy.git