SSHキーをBitbucketに登録してサーバーでgitを使えるようにする

1.Bitbucket用のSSHキーを生成する

$ cd ~/.ssh
$ mkdir bitbucket
$ cd bitbucket
$ ssh-keygen -t rsa -C "bitbucketにユーザ登録しているメールアドレス"

ここで以下のように質問が出るので設定をします。
Enter file in which to save the key (/Users/your_user_directory/.ssh/bitbucket/id_rsa): id_rsa.bitbucket.org

※、パスワードの設定について2回質問されますが、EnterでOKです

id_rsa.bitbucket.org
id_rsa.bitbucket.org.pub

が生成されます。ここでアクセス権限を修正します
$ chmod 600 id_rsa.bitbucket.org

2.configの追加

vim ~/.ssh/config

※、以下を追加
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket/id_rsa.bitbucket.org
User git
Port 22
TCPKeepAlive yes
IdentitiesOnly yes

3.https://bitbucket.org/ へのキーの登録
ログイン後、以下のコマンドを実施します
 ・トップページから「Manage Account」を選択します
 ・Manage Accountでは左メニューの「SSH keys」を選択します
 ・「Add Key」を選択します。登録ウインドウでは
  Label 「任意の表示名」
  Key 「id_rsa.bitbucket.org.pubの内容(メールアドレスを含む)」
 を入力して「Add Key」として追加を行います。

4.接続テスト

$ ssh -T git@bitbucket.org

※、正しくSSHが設定されていれば、以下のように表示されます
conq: logged in as ユーザ名.

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

5.git clone

$ git clone git@bitbucket.org:ユーザ名/リポジトリ名.git

※、実施後実行したディレクトリにリポジトリ名のディレクトリが作成されて
ファイルが展開されます

参考サイト
http://qiita.com/MegaBlackLabel/items/54f2a874acda6cb763f0

タイトルとURLをコピーしました