RailsチュートリアルのBitbucketの設定項目がありましたが、初心者の人にはちょっと難しいと思ったので、ここにメモ。
1- 既に公開鍵が作成されているか確認
cat ~/.ssh/id_rsa.pub
を実行して公開鍵が既に作成されいるか確認する。作成されていなければ、No such file or directory1
と標示されます。
既に作成されている場合は、3にジャンプしてください。
1
2
|
$ cat ~/.ssh/id_rsa.pub
cat: /home/vagrant/.ssh/id_rsa.pub: そのようなファイルやディレクトリはありません
|
2- SSH認証の公開鍵と秘密鍵をつくる
SSH Keyを作成する。ssh-keygen -t rsa -C aaa@mail
を実行。
いろいろ聞かれるがEnterを押す。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
$ cd ~/.ssh
~/.ssh$ ssh-keygen -t rsa -C aaa@mail ←自分のメールアドレス
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/vagrant/.ssh/id_rsa.
Your public key has been saved in /home/vagrant/.ssh/id_rsa.pub.
The key fingerprint is:
******************************************************* aaa@mail
The key's randomart image is:
+---[RSA 2048]----+
| . .+.. o|
| + . . + +.|
| . + o * . *oo|
| + o + B +.Xo|
| . + S + +.B.+|
| . . o . ooo.|
| E ..o+o|
| o +. o|
| .... . |
+----[SHA256]-----+
|
鍵の生成がが完了したら2つのファイルができます。
1
2
|
id_rsa: 秘密鍵
id_rsa.pub: 公開鍵、 Bitbucketに登録する
|
ファイルのパーミッションを変更して、セキュリティを変更します。
PC側へのSSHキーの設定
~/.ssh/config
のファイルの末尾に次の内容を追加。
コピペしたら:wq
を実行して保存。間違ったりして保存したくない場合は:q!
を実行。
Escキー
を押したら:
が押せるはずです。
1
2
3
4
|
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa
User git
|
3- Bitbucketに公開鍵を登録する
左下にある人のアイコンを選択するとBitbucketの設定
が標示されるので、それを選択します。

セキュリティにあるSSH鍵を選択。

鍵を追加クリック。

ラベルには適当な名前をつけ以下のコマンド実行し、keyにペーストします。

1
|
$ cat ~/.ssh/id_rsa.pub | xclip -sel clip
|
bash: xclip: コマンドが見つかりませんとでたら、とりあえずはこれでもイケる。
ssh-rsaからメールアドレスのまで全部をコピーする。
1
2
3
4
5
|
~$ cat ~/.ssh/id_rsa.pub
ssh-rsa
**************************************************************************
**************************************************************************
aaa@mail
|
接続できるか確認
途中でAre you sure you want to continue connecting (yes/no)?
と聞かれますので、yes
と答える。
1
2
3
4
5
|
$ ssh -T [email protected]
logged in as アカウント名.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
|
問題なく接続されていることを確認。
See Also