SSH キーを作成する
このページでは、SSH キーの作成方法について説明します。
SSH keys can be used to establish a secure connection with Bitbucket Data Center and Server for:
- ローカル マシンから Git 操作を実行する場合
- when another system or process needs access to repositories in Bitbucket (for example your build server)
The SSH key needs to be added to Bitbucket, and your Bitbucket administrator must have enabled SSH access to Git repositories before you can make use of the key.
- ED25519
- RSA2 (we recommend you use a key size of at least 2048 bits)
- ECDSA
- DSA (we recommend you use other key types)
You can use an existing SSH key with Bitbucket if you want, in which case you can go straight to either SSH user keys for personal use or SSH access keys for system use.
このページの内容
Windows での SSH キーの作成
1. 既存の SSH キーの確認
You should check for existing SSH keys on your local computer. You can use an existing SSH key with Bitbucket if you want, in which case you can go straight to either SSH user keys for personal use or SSH access keys for system use.
コマンド プロンプトを開いて以下を実行します。
cd %userprofile%/.ssh
"No such file or directory" と表示された場合、既存のキーはありません。 ステップ 3 に進みます。
すでにキーを持っているかどうかを確認します。
dir id_*
既存のキーがある場合はそれを使用することもできます。「個人用の SSH ユーザー キー」または「システム用の SSH アクセス キー」をご参照ください。
2. 古い SSH キーのバックアップ
If you have existing SSH keys, but you don't want to use them when connecting to Bitbucket, you should back those up.
ローカル コンピューターのコマンド プロンプトで、以下を実行します。
mkdir key_backup
copy id_ed25519* key_backup
3. 新しい SSH キーの生成
使用する既存の SSH キーを持っていない場合は、以下を生成します。
- ローカル コンピューターに管理者としてログインします。
コマンド プロンプトで以下を実行します。
ssh-keygen -t ed25519 -C "your_email@example.com"
Note: If you're using a legacy system that doesn't support the ED25519 algorithm, run:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
キーとメール アドレスを関連付けておくと、あとからキーを識別するのに役立ちます。
Note that the
ssh-keygen
command is only available if you have already installed Git (with Git Bash).
You'll see a response similar to this:C:\Users\fperez>ssh-keygen -t ed25519 -C "your_email@example.com" Generating public/private ed25519 key pair. Enter file in which to save the key (/c/Users/fperez/.ssh/id_ed25519):
- Just press <Enter> to accept the default location and file name. If the
.ssh
directory doesn't exist, the system creates one for you. プロンプトが表示されたら、パス フレーズの入力と確認入力を行います。全体の流れは次のようになります。
C:\Users\fperez>ssh-keygen -t ed25519 -C "your_email@example.com" Generating public/private ed25519 key pair. Enter file in which to save the key (/c/Users/fperez/.ssh/id_ed25519): Created directory '/c/Users/fperez/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in c/Users/fperez/.ssh/id_ed25519. Your public key has been saved in c/Users/fperez/.ssh/id_ed25519.pub. The key fingerprint is: SHA256:wvaHYeLtY6+DlvV5sFZgDi3abcdefghijklmnopqrstuvw your_email@example.com
You're done and you can now go to either SSH user keys for personal use or SSH access keys for system use.
Linux および macOS での SSH キーの作成
1. 既存の SSH キーの確認
You should check for existing SSH keys on your local computer. You can use an existing SSH key with Bitbucket if you want, in which case you can go straight to either SSH user keys for personal use or SSH access keys for system use.
ターミナルを開いて、以下を実行します。
cd ~/.ssh
- "No such file or directory" と表示された場合、既存のキーはありません。 ステップ 3 に進みます。
すでにキーを持っているかどうかを確認します。
ls id_*
- If there are existing keys, you may want to use them; go to either SSH user keys for personal use or SSH access keys for system use.
2. 古い SSH キーのバックアップ
If you have existing SSH keys, but you don't want to use them when connecting to Bitbucket, you should back those up.
以下のコマンドを実行して、ローカル コンピューターのターミナル内でこれを実行します。
mkdir key_backup
cp id_ed25519* key_backup
3. 新しいキーの生成
使用する既存の SSH キーを持っていない場合は、以下を生成します。
ローカル コンピューターででターミナルを開き、以下を入力します。
ssh-keygen -t ed25519 -C "your_email@example.com"
Note: If you're using a legacy system that doesn't support the ED25519 algorithm, use:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
キーとメール アドレスを関連付けておくと、あとからキーを識別するのに役立ちます。
次のような応答が表示されます。
fperez@homemac ~ % ssh-keygen -t ed25519 -C fperez@email.com Generating public/private ed25519 key pair. Enter file in which to save the key (/Users/fperez/.ssh/id_ed25519):
- Just press <Enter> to accept the default location and file name. If the
.ssh
directory doesn't exist, the system creates one for you. プロンプトが表示されたら、パス フレーズの入力と確認入力を行います。
全体の流れは次のようになります。fperez@homemac ~ % ssh-keygen -t ed25519 -C fperez@email.com Generating public/private ed25519 key pair. Enter file in which to save the key (/Users/fperez/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/fperez/.ssh/id_ed25519. Your public key has been saved in /Users/fperez/.ssh/id_ed25519.pub. The key fingerprint is: SHA256:gTVWKbn41z6JgBNu3wYjLC4abcdefghijklmnopqrstuvwxy fperez@email.com The key's randomart image is: +--[ED25519 256]--+ |==+. +o.. | |.oE. +o.. | | . ...o | | .o... | | oo+S . | | + ..B = . . | |.+.+.oo+ * o . | |o++.o+ . + + | |B+ o. . . | +----[SHA256]-----+ fperez@homemac ~ %
- You're done and you can now go to either SSH user keys for personal use or SSH access keys for system use.