SSH キーをまだお持ちでない場合は、新しい SSH キーを生成する必要があります。 SSH キーを持っているかどうかわからない場合は、既存のキーをチェックします。
SSH キーを使用するたびにパスフレーズを再入力したくない場合は、キーを SSH エージェントに追加できます。これにより、SSH キーが管理されパスフレーズが記憶されます。
新しい SSH キーを生成する
-
ターミナルターミナルGit Bashを開いてください。
-
以下のテキストを貼り付けます。メールアドレスは自分の GitHub Enterprise Server メールアドレスに置き換えてください。
$ ssh-keygen -t ed25519 -C "your_email@example.com"これにより、入力したメールアドレスをラベルとして使用して新しい SSH キーが作成されます。注釈: Ed25519 アルゴリズムをサポートしないレガシーシステムを使用している場合は、以下を使用します。
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"> Generating public/private ed25519 key pair. -
「Enter a file in which to save the key」というメッセージが表示されたら、Enter キーを押します。 これにより、デフォルトのファイル場所が受け入れられます。
> Enter a file in which to save the key (/Users/you/.ssh/id_ed25519): [Press enter]> Enter a file in which to save the key (/c/Users/you/.ssh/id_ed25519):[Press enter]> Enter a file in which to save the key (/home/you/.ssh/id_ed25519): [Press enter] -
プロンプトで、安全なパスフレーズを入力します。 詳細は「SSH キーのパスフレーズを使う」を参照してください。
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
SSH キーを ssh-agent に追加する
キーを管理するために新しい SSH キーを ssh-agent に追加する前に、既存の SSH キーの確認と新しい SSH キーの生成を済ませておく必要があります。 エージェントに SSH キーを追加する際、デフォルトの macOS の ssh-add コマンドを使用してください。[macports] macports (https://www.macports.org/)、[homebrew] (http://brew.sh/)、またはその他の外部ソースによってインストールされたアプリケーションは使用しないでください。
-
バックグラウンドでssh-agentを開始します。
$ eval "$(ssh-agent -s)" > Agent pid 59566 -
macOS Sierra 10.12.2 以降を使用している場合は、
~/.ssh/configファイルを修正して、キーが自動で ssh-agent に読み込まれ、キーチェーンにパスフレーズが記憶されるようにする必要があります。-
まず、
~/.ssh/configファイルがデフォルトの場所にあるかどうかを確認します。$ open ~/.ssh/config > The file /Users/you/.ssh/config does not exist. -
ファイルがない場合は、ファイルを作成します。
$ touch ~/.ssh/config -
~/.ssh/configファイルを開いて修正し、id_ed25519キーのデフォルトの場所と名前を使用していない場合は~/.ssh/id_ed25519を置き換えます。Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519注釈: キーにパスフレーズを追加しない場合は、
UseKeychain行を省略してください。
-
-
SSH 秘密鍵を ssh-agent に追加して、パスフレーズをキーチェーンに保存します。 If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add -K ~/.ssh/id_ed25519メモ:
-Kオプションは、ssh-addの Apple の標準バージョン内にあり、ssh-agent に SSH キーを追加する際にキーチェーンにパスフレーズを保存します。 キーにパスフレーズを追加しない場合は、-Kオプションを指定せずにコマンドを実行します。Apple の標準バージョンをインストールしていない場合は、エラーが発生する場合があります。 このエラーの解決方法についての詳細は、「エラー: ssh-add: illegal option -- K」を参照してください。
GitHub Desktopをインストールしてあるなら、それを使ってSSHキーを扱わずにリポジトリをクローンできます。
-
ssh-agent が実行されていることを確認します. 「SSH キーパスフレーズで操作する」の「ssh-agent を自動起動する」の手順を使用するか、手動で開始できます。
# start the ssh-agent in the background $ eval `ssh-agent -s` > Agent pid 59566 -
SSH プライベートキーを ssh-agent に追加します。 If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_ed25519
-
バックグラウンドでssh-agentを開始します。
$ eval "$(ssh-agent -s)" > Agent pid 59566 -
SSH プライベートキーを ssh-agent に追加します。 If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_ed25519