暗号鍵の生成
# sshのセッティングディレクトリに移動
$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_git_rsa
# Enter passphrase (empty for no passphrase):
# Enter same passphrase again:
GitHubへの公開鍵のアップロード
以下URLで公開鍵の設定
https://github.com/settings/ssh
ssh接続の設定
~/.ssh/conifg
Host github
HostName github.com
IdentityFile ~/.ssh/main_rsa
User git
Port 22
TCPKeepAlive yes
IdentitiesOnly yes
Host github-sub
HostName github.com
IdentityFile ~/.ssh/sub_rsa
User git
Port 22
TCPKeepAlive yes
IdentitiesOnly yes
github-subとgithubは任意
IdentityFileのファイル名も任意
githubへのssh接続確認
# ssh接続確認 (<HOST NAME>には「github-sub」などが入る)
$ ssh -T <HOST NAME>
# Hi ******! You've successfully authenticated, but GitHub does not provide shell access.
# git cloneを実行 (ssh用のURLをコピーし、HOST NAMEを書き換える)
$ git clone <HOST NAME>:******/******.git
参考
GitHubでssh接続する手順~公開鍵・秘密鍵の生成から~
https://qiita.com/shizuma/items/2b2f873a0034839e47ce
複数のgitアカウントを使用する場合
https://qiita.com/yamataku29/items/4744c9c70ad793c83b82