100
93

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 5 years have passed since last update.

ターミナルからgithubのリポジトリにアクセスする設定(sshの設定)

Posted at

GitHub Helpページを参考にしてます。
https://help.github.com/articles/generating-ssh-keys

まず、鍵を作成。鍵のファイル名はgithub_id_rsaにしています。

$ cd ~/.ssh/
$ ssh-keygen -t rsa -C "メールアドレス"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ユーザー名/.ssh/id_rsa): github_id_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in github_id_rsa.
Your public key has been saved in github_id_rsa.pub.
(省略)

クリップボードに公開鍵をコピー。pbcopyコマンドでコピーします。

$ pbcopy < github_id_rsa.pub

GitHub Webページの「User settings」「SSH Key」へ。
「Add SSH key」に進んでクリップボートにコピーした公開鍵を貼り付けます。

これで設定完了です。
ターミナルのsshコマンドで接続確認を行います。

$ ssh -l git -i ~/.ssh/github_id_rsa github.com                                                       
PTY allocation request failed on channel 0
Hi pakiln! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

接続できました。

次はおまけです。sshコマンドのオプションを省略する設定です。

$ vi ~/.ssh/config
Host github.com
 HostName      github.com
 IdentityFile  ~/.ssh/github_id_rsa
 User          git

この設定をしておくと、

$ ssh github.com

$ ssh -l git -i ~/.ssh/github_id_rsa github.com                                                       

を実行したことになります。

100
93
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
100
93

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?