Skip to content

Instantly share code, notes, and snippets.

@foomin10
Last active October 17, 2015 16:39
Show Gist options
  • Save foomin10/0d6a16ecc38d0dea36a5 to your computer and use it in GitHub Desktop.
Save foomin10/0d6a16ecc38d0dea36a5 to your computer and use it in GitHub Desktop.
ssh-keygen メモ

参考

[Gehirn RS2] SSHキーをBitbucketに登録してgitコマンドを使えるようにする - Qiita
http://qiita.com/MegaBlackLabel/items/54f2a874acda6cb763f0

SSHキーの生成

ssh-keygen-C オプションはコメント。指定しないと ユーザー名@コンピュータ名 のようになる。

-f オプションで保存するファイル名を指定する。

% cd ~/.ssh
% mkdir github
% ssh-keygen -t rsa -C "foomin10@gmail.com" -f "github/id_rsa"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

% chmod 600 github/id_rsa
% cd ~/.ssh
% mkdir bitbucket
% ssh-keygen -t rsa -C "foomin10@gmail.com" -f "bitbucket/id_rsa"
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

% chmod 600 bitbucket/id_rsa

config の編集

~/.ssh/config を作成する

Host github.com
  IdentityFile ~/.ssh/github/id_rsa
  User git
  HostName github.com
  Port 22
  TCPKeepAlive yes
  IdentitiesOnly yes
Host bitbucket.org
  IdentityFile ~/.ssh/bitbucket/id_rsa
  User git
  HostName bitbucket.org
  Port 22
  TCPKeepAlive yes
  IdentitiesOnly yes

chmod 600 ~/.ssh/config でパーミッションを設定

SSHキーの登録

接続テスト

% ssh -T git@github.com
Hi foomin10! You've successfully authenticated, but GitHub does not provide shell access.
% ssh -T git@bitbucket.org
logged in as foomin10.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

ディレクトリ構造

~/
  .ssh/
    bitbucket/
      id_rsa
      id_rsa.pub
    github/
      id_rsa
      id_rsa.pub
    config
    known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment