新しい SSH キーを生成して ssh-agent に追加する
既存の SSH キーをチェックした後、新しい SSH キーを生成して認証に使用し、ssh-agent に追加できます。
SSH キーをまだお持ちでない場合は、新しい SSH キーを生成 する必要があります。 SSH キーを持っているかどうかわからない場合は、既存のキー をチェックします。
SSH キーを使用するたびにパスフレーズを再入力したくない場合は、キーを SSH エージェントに追加 できます。これにより、SSH キーが管理されパスフレーズが記憶されます。
ターミナル ターミナル Git Bash を開いてください。
以下のテキストを貼り付けます。メールアドレスは自分の GitHub Enterprise Server メールアドレスに置き換えてください。
$ ssh-keygen -t ed25519 -C "your_email@example.com "
注釈: Ed25519 アルゴリズムをサポートしないレガシーシステムを使用している場合は、以下を使用します。
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
これにより、入力したメールアドレスをラベルとして使用して新しい SSH キーが作成されます。
> 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 キーの生成 を済ませておく必要があります。 エージェントに 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 」を参照してください。
SSH キーを GitHub アカウントに追加します 。
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 キーを GitHub アカウントに追加します 。
バックグラウンドで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
SSH キーを GitHub アカウントに追加します 。