概要
MacからGithubにSSHを利用して接続をするための設定方法をメモしました。
参考
ssh key 作成方法
sshkeyの作成
ssh-keygen -t ed25519 -C "your_email@example.com"
を実行し、ssh keyを作成します。
your_email@example.com
はgithubのアカウントに紐付いたメールアドレスを使用してください。
$ ssh-keygen -t ed25519 -C "your_email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/xxxxxx/.ssh/id_ed25519): /Users/xxxxxx/.ssh/id_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_github.
Your public key has been saved in id_github.pub.
key(ファイル名)は/Users/xxxxxx/.ssh/id_github
と指定します。
passphraseは何も入力せずにエンターを押します。
config設定
configの設定をします。
$ vi ~/.ssh/config
以下を追記します。
Host github github.com
HostName github.com
IdentityFile ~/.ssh/id_github
User git
権限を変更します。
$ chmod 600 ~/.ssh/config
Githubに公開鍵を登録
以下のURLにアクセスしてkeyを登録します。
https://github.com/settings/ssh/new
Title はどの端末で利用するか分かるようにしておくと良いと思います。
例: MacBook Pro (15-inch, 2018) など
key は cat ~/.ssh/id_github.pub
で確認できる内容をそのまま貼り付けます。
以下、実行例。
cat ~/.ssh/id_github.pub
# 以下をコピー
ssh-xxxx xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx your_email@example.com
SSH接続のテスト
$ ssh -T github
# 以下のように出力されれば設定完了です。
Hi [your_account]! You've successfully authenticated, but GitHub does not provide shell access.
これで設定完了です。
あとは、clone するときに https
ではなく ssh
を選択して、git remote add origin xxxxxxx
をすればOKです。
(すでに登録している場合はgit remote set-url origin xxxxx
)