環境: Windows
SSH鍵の作成
Git Bashを開き、以下を実行
$ ssh-keygen -f ~/.ssh/<personalid> -C "<personalid>"
※personalidは任意の名前
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/<username>/.ssh/<personalid>.
Your public key has been saved in /c/Users/<username>/.ssh/<personalid>.pub.
The key fingerprint is:
SHA256:vmLliyNTonIWQIHI7yXfLb1MUe/Zz7qwoSc5H+iL6eM <username>
The key's randomart image is:
+---[RSA 2048]----+
|+.. |
|oo . |
|. . . . |
|. o . . . |
| .. + . S . . o |
| .....+.+ . o . |
| o o o= o.+ ..|
|. + o +.oB+..= o|
| + +.=Eo+*o oo |
+----[SHA256]-----+
公開鍵の追加
作成された公開鍵を、Bitbucket.orgの[セキュリティ]-[SSH鍵]-[鍵を追加]から、追加する
秘密鍵の配置
任意のディレクトリに配置する
例:
~/.ssh/bitbucket-org_<personalid>/<personalid>
~/.ssh/configの作成
~/.ssh/config
Host bitbucket
Hostname bitbucket.org
IdentityFile ~/.ssh/bitbucket-org_<personalid>/<personalid>
User git
Port 22
# Following may not be necessary
TCPKeepAlive yes
IdentitiesOnly yes
※Hostはalias
※IdentityFileに秘密鍵の場所を指定
ssh接続確認
$ ssh -T bitbucket
実行結果:
logged in as ..
と出れば、成功
gitのリモートURLの設定
gitのディレクトリで、リモートURLを設定する
$ git remote set-url origin <.ssh/configで設定する"Host"(つまり、bitbucket)>:<Bitbucketのユーザ名>/<リポジトリ名>.git
git pushが出来れば成功