新しく働き始めた会社のPCのセットアップをしているのだが、
PC新規立ち上げが久々過ぎてGitHubのSSH設定方法を忘れかけてるので備忘録。
% git clone git@github.com:${account name}/${repository name}.git
Cloning into '${repository name}'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
前提
- GitHubに登録していること。
- Mac OS 13.5.1 Ventura (22G90)
認証キーの作成
※ここではパスフレーズ無しでgithub_id_rsa
という名前を指定して作成しています。
% cd ~/.ssh
% ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mitsuaki.ihara/.ssh/id_rsa): github_id_rsa
Enter passphrase (empty for no passphrase): ${空でエンター}
Enter same passphrase again: ${空でエンター}
Your identification has been saved in github_id_rsa
Your public key has been saved in github_id_rsa.pub
公開鍵をGitHubにアップする
公開鍵の中身をクリップボードにコピーする。
% pbcopy < ~/.ssh/github_id_rsa.pub
SSH keysからNew SSH Key
をタップし、下記を入力
- Title:${どのPCか分かりやすくなる鍵の名前推奨}
- Key type:Authentication Key
- Key:${コピーした公開鍵}
接続確認
作成した鍵情報を指定しつつGitHubに接続する。
% ssh -T git@github.com -i ~/.ssh/github_id_rsa
Hi mitsuaki1229! You've successfully authenticated, but GitHub does not provide shell access.
コンフィグの作成
鍵情報を指定しないとデフォルトの鍵情報を見に行ってしまうため、GitHubに接続する際の情報を指定する。
% touch ~/.ssh/config
% vim ~/.ssh/config
下記を追記
Host github github.com
HostName github.com
IdentityFile ~/.ssh/github_id_rsa
User git
キー指定無しで接続出来ることを確認。
% ssh -T git@github.com
Hi mitsuaki1229! You've successfully authenticated, but GitHub does not provide shell access.
リポジトリのクローン
クローンの実施。
% git clone git@github.com:${account name}/${repository name}.git
参考