0
1

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.

Bitbucket.orgをSSH鍵で操作する方法

Posted at

環境: 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が出来れば成功

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?