0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

何度やっても忘れるSSH化の備忘録

Posted at

PCを買い替える度に設定方法を調べているので備忘録で残しておきます。

新しいSSHキーを生成する

下記をコピペして、メールアドレスは自分のものに書き換える

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

公開鍵作成されたことが表記される

Generating public/private ed25519 key pair.

パスワードを入力

Enter passphrase (empty for no passphrase):

こうなればOK!!

Your identification has been saved in /Users/you/.ssh/id_ed25519
Your public key has been saved in /Users/you/.ssh/id_ed25519.pub
The key fingerprint is:
SHA111:iLbtddYTPIJr6T+EUuJY5b8i4c9KUpTeA/zB+Xt111w example@gmail.com
The key's randomart image is:
+--[ED25519 111]--+
|            o.   |
|           o o. .|
|          . + o+ |
|     . .  +o.+ oo|
|    o . S* oB.. +|
|   . o  o +.o+.+|
|    . ....=o+. E+|
|     . .o. o.. +|
|      .  o++..   |
+----[SHA111]-----+

新しいSSHキーを生成する

下記を実行する

eval "$(ssh-agent -s)"

ファイルが存在するか一応確認する

open ~/.ssh/config
The file /Users/you/.ssh/config does not exist.

ない場合は作成

touch ~/.ssh/config

ある場合は開く

open ~/.ssh/config

これを貼り付け

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

変更が反映されているか確認

open ~/.ssh/config

下記をコピペして、SSH 秘密鍵を ssh-agent に追加して、パスワードをキーチェーンに保存する

ssh-add -K ~/.ssh/id_ed25519

Githubアカウントへの新しいSSHキーの追加

下記をコピペして実行する

pbcopy < ~/.ssh/id_ed25519.pub

pbcopyコマンドが使えなければ、直接ファイルを開いてコピーする

スクリーンショット 2025-03-26 14.32.43.png

こんな感じに表示されるので、コピーする

ssh-ed25519 hogefugahogefugahogefugahogefugahogefugahogefugahogefugahogefugaho example@gmail.com

あとはGihubの設定から SSH and GPG keys を選択し先ほどコピーした物を貼り付けます
スクリーンショット 2025-03-26 14.34.52.png

SSH keys 画面に下記のように追加されていればOK
スクリーンショット 2025-03-26 14.37.27.png

SSH 接続をテストする

下記を実行する

ssh -T git@github.com

このように表示されればOK!!!

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

最後に一応git cloneが実行できるか確認してみましょう!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?