LoginSignup
12
10

More than 3 years have passed since last update.

GitHubの初期設定〜GitHubにSSH接続するまでの設定手順〜

Last updated at Posted at 2015-11-03

はじめに

GitHubで開発するための初期設定である、GitHubにSSH接続するまでの設定手順について書いています。

毎度、新しい環境にGitHubの設定をする度に調べている自分がいたので自分向けの備忘録として書いております。あしからず。誰かのお役に少しでもなれましたら

前提

・GitHubのアカウントは登録済
・クライアントPCはMacを前提としています

公開鍵と秘密鍵の作成

GitHubにssh接続するためには公開鍵をGitHubに登録する必要があります
クライアントPC(Mac)に公開鍵と秘密鍵を作成します

鍵を作るためディレクトリへ移動します

$ cd ~/.ssh/

下記のコマンドを叩いて、鍵を生成します
※ 3回くらい確認を求められますが、enterでOKです

$ ssh-keygen -t rsa

鍵を確認します
id_rsa(秘密鍵)と id_rsa.pub(公開鍵)のファイルが作られていればOKです
id_rsa.pub がGitHubへ登録する公開鍵となります

$ ls -l

クライアント側(Mac)へのSSHキーの設定

今後、GitHubの接続先を複数管理したりする時に楽なのでクライアント側にSSHの設定を書いておきます。

$ vim ~/.ssh/config
~/.ssh/config
Host github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa
  User git

公開鍵をGitHubに登録

GitHubにログインし下記ページへ移動します
https://github.com/settings/ssh

画面右上 「Add SSH Key」 をクリックします

スクリーンショット(2015-11-03 19.18.20).png

"title" の項目に公開鍵の名前(任意の名前でOK)と、"key" の項目に先ほど作成した公開鍵の内容を貼付けます。
内容を確認し、"Add key" をクリックします

クリップボードにコピー(mac)
$ pbcopy < ~/.ssh/id_rsa.pub
クリップボードにコピー(windows)
$ clip < ~/.ssh/id_rsa.pub

スクリーンショット(2015-11-03 19.22.40).png

接続のテスト

$ ssh -T git@github.com

下記のような表示がされていれば成功です

Hi {account-name}! You've successfully authenticated, but GitHub does not provide shell access.

以上で完了です。お疲れさまでした :kissing_heart: :ghost:

12
10
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
12
10