LoginSignup
0
1

More than 1 year has passed since last update.

Mac githubのSSH設定

Last updated at Posted at 2022-04-25

今回はgithubの公式ドキュメントに沿った形でSSH設定を行っていきたいと思います。
設定し終えれば、githubでSSH通信が使える様になります。

前提

使用端末はMacで、githubの初期設定は済んでいる事。

SSH設定の手順

1. まずは、sshキーが存在しているかをターミナルで確認する

$ ls -al ~/.ssh

2. sshキーを作成する。“”の中に自分のメールアドレスを入力する。

$ ssh-keygen -t ed25519 -C "your_email@example.com"

入力後、以下が出力されればSSHキーが作成されています。

Generating public/private algorithm key pair.

3. プロンプトに「ファイル名の置き場所とパスフレーズをどうする?」と聞かれますが、こだわりがなければ全てEnter押せばOK。

Enter a file in which to save the key (/Users/you/.ssh/id_algorithm): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

4. ssh-agentを起動する。

$ eval "$(ssh-agent -s)"

5. ~/.ssh/configがデフォルトの場所に存在するかを確認する。(存在していれば6.は飛ばして良い。)

$ open ~/.ssh/config

6. 先程の5.でThe file /Users/you/.ssh/config does not exist.と帰ってきた場合はファイルを作成する。

$ touch ~/.ssh/config

7. ~/.ssh/configを開き、以下のようにファイルを更新する。

Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

8. 秘密鍵をssh-agentに追加する。パスフレーズを追加していない為、-Kオプションは付けない。

$ ssh-add ~/.ssh/id_ed25519

9. pbcopyコマンドでssh公開鍵をコピーする。

$ pbcopy < ~/.ssh/id_ed25519.pub

githubの操作編

10. github.comでプロフィール画像をクリックしてSettingsを開く。次にSSH and GPG keysを開きNew SSH keyをクリックする。

11. title欄は好みの名前でKeyの欄にはpbcopyでコピーしたものをペーストで貼り付ける。

ターミナルに戻る

12. ssh接続テストをする。

$ ssh -T git@github.com

以下のように自分の名前が帰って来ればOK!

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

お疲れ様でした!

参照

公式githubドキュメント
https://docs.github.com/ja/authentication/connecting-to-github-with-ssh/about-ssh

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1