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キーを作成してgithubに登録する方法

Last updated at Posted at 2025-04-09

鍵ペアの作成

ホームディレクトリに移って、下記コマンドから.から始まる隠しファイルがないか確認する。

ls -a

ない場合は下記コマンドで鍵ペアを入れるための.sshフォルダを作成する。

mkdir ~/.ssh

このコマンドで鍵ペア(秘密鍵、公開鍵)が作成できる。

ssh-keygen -t ed25519

そしたら下記について聞かれるのですべてEnterをおす。
Monosnap yurikawasha — yurikawasha@yurikawashanoMacBook-Pro — ~ — -zsh — 93×32 2025-04-09 23-46-59.png

Enterをおして、こんな感じの図形が出てきたら鍵の作成は成功。
Monosnap yurikawasha — yurikawasha@yurikawashanoMacBook-Pro — ~ — -zsh — 93×32 2025-04-09 23-45-34.png

次に先ほど作成した.sshフォルダの中に移動する。

cd ~/.ssh

lsでid_rsa(秘密鍵)、id_rsa.pub(公開鍵)が作成されているか調べる。

githubへの登録

鍵の登録はここで行う。
https://github.com/settings/keys

そしたら、右上のNew SSH keyをクリック。
Monosnap SSH and GPG keys 2025-04-10 00-07-03.png

中身はこんな感じ。
Monosnap Add new SSH key 2025-04-10 00-08-25.png

登録できたら、ターミナル上でこれを打ち込んで確認。

ssh -T git@github.com

yesかnoのどちらか聞かれるので、下記を見て、フィンガープリントが間違っていなかったら、yesを入力
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints

自分のgithub上の名前が返ってきたら成功です。

追記:
VScode上でpushする場合はターミナル上で下記の設定が必須。

 git config --global user.name "自分の名前" 
 git config --global user.email "自分のメールアドレス" 

設定ができているか確認。

 git config --global --list

2025/05/05 追記
鍵ペアの作成方法でssh-keygen -t rsa を記載していましたが、この鍵暗号方式は古いので使わないでください。

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?