0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GithubにSSH接続する手順(2021) - sshkey作成・設定・接続テスト

Last updated at Posted at 2021-10-30

概要

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

以下を追記します。

~/.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) など

keycat ~/.ssh/id_github.pub で確認できる内容をそのまま貼り付けます。

以下、実行例。

cat ~/.ssh/id_github.pub
# 以下をコピー
ssh-xxxx xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxx your_email@example.com

sshkey-new.png

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

git-clone.png

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?