秘密鍵と公開鍵の作成
$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_git -N ""
$ touch ~/.ssh/config
$ chmod 600 ~/.ssh/config
SSH設定ファイルの設定
SSHクライアント用設定ファイルに、Githubの接続情報を追記します。
$ nano ~/.ssh/config
以下の内容を記述します。
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_git
Port 22
公開鍵をGithubに登録する
作成した公開鍵の情報を出力します。
ssh-rsa xxxxxxxxxxxxx admin@raspberrypi
のような長い文字列が出力されます。
$ cat ~/.ssh/id_rsa_git.pub
Githubアカウントにログインして、「Settings」「SSH and GPG keys」を開きます。
SSH Keys の「New SSH Key」ボタンをクリックして、先ほど出力した公開鍵の情報をコピー&ペーストして登録すれば完了です。
(Titleには、公開鍵を識別できように端末名など分かるものを適当に設定すれば大丈夫です)
Gitの初期設定
またGitを使用するために、ユーザー名とメールアドレスの個人識別情報を設定しておきます。
$ git config --global user.name "<ユーザ名>"
$ git config --global user.email hogehoge@example.com