SSH キーを作成する
このページでは、SSH キーの作成方法について説明します。
次の場合、SSH キーを使用して Bitbucket Server との安全な接続を確立できます。
- ローカル マシンから Git 操作を実行する場合
- 別のシステムやプロセスで Bitbucket Server 内のリポジトリにアクセスする必要がある場合 (ビルド サーバーなど)
The SSH key needs to be added to Bitbucket Server, and your Bitbucket Server administrator must have enabled SSH access to Git repositories before you can make use of the key.
Bitbucket Server supports DSA, RSA2, and Ed25519 key types. RSA1 is not supported
必要も応じて Bitbucket Server で既存の SSH キーを使用できます。この場合、「個人用の SSH ユーザー キー」または「システム用の SSH アクセス キー」をご参照ください。
このページの内容
Windows での SSH キーの作成
1. 既存の SSH キーの確認
You should check for existing SSH keys on your local computer. You can use an existing SSH key with Bitbucket Server 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 キーのバックアップ
既存の SSH キーがあるが、それを Bitbucket Server への接続時に使用したくない場合、それをバックアップする必要があります。
ローカル コンピューターのコマンド プロンプトで、以下を実行します。
mkdir key_backup
copy id_ed25519* key_backup
3. 新しい SSH キーの生成
使用する既存の SSH キーを持っていない場合は、以下を生成します。
- ローカル コンピューターに管理者としてログインします。
コマンド プロンプトで以下を実行します。
ssh-keygen -t ed25519 -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\ASUS>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/ASUS/.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\ASUS>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/ASUS/.ssh/id_ed25519): Created directory '/c/Users/ASUS/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in c/Users/ASUS/.ssh/id_ed25519. Your public key has been saved in c/Users/ASUS/.ssh/id_ed25519.pub. The key fingerprint is: SHA256:wvaHYeLtY6+DlvV5sFZgDi3RTAe8R2KY23N78qrGqJE your_email@example.com
これで完了です。「個人用の SSH ユーザー キー」または「システム用の SSH アクセス キー」にお進みください。
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 Server 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 キーのバックアップ
既存の SSH キーがあるが、それを Bitbucket Server への接続時に使用したくない場合、それをバックアップする必要があります。
以下のコマンドを実行して、ローカル コンピューターのターミナル内でこれを実行します。
mkdir key_backup
cp id_ed25519* key_backup
3. 新しいキーの生成
使用する既存の SSH キーを持っていない場合は、以下を生成します。
ローカル コンピューターででターミナルを開き、以下を入力します。
ssh-keygen -t ed25519 -C "your_email@example.com"
キーとメール アドレスを関連付けておくと、あとからキーを識別するのに役立ちます。
次のような応答が表示されます。
chaiss@C02FP1JWMD6V ~ % ssh-keygen -t ed25519 -C chaiss@email.com Generating public/private ed25519 key pair. Enter file in which to save the key (/Users/chaiss/.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. プロンプトが表示されたら、パス フレーズの入力と確認入力を行います。
全体の流れは次のようになります。chaiss@C02FP1JWMD6V ~ % ssh-keygen -t ed25519 -C chaiss@email.com Generating public/private ed25519 key pair. Enter file in which to save the key (/Users/chaiss/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/chaiss/.ssh/id_ed25519. Your public key has been saved in /Users/chaiss/.ssh/id_ed25519.pub. The key fingerprint is: SHA256:gTVWKbn41z6JgBNu3wYjLC4H6oW5bmhaXyaVABwmEtE chaiss@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]-----+ chaiss@C02FP1JWMD6V ~ %
- これで完了です。「個人用の SSH ユーザー キー」または「システム用の SSH アクセス キー」にお進みください。