About addition of SSH keys to your account
You can access and write data in repositories on GitHub.com using SSH (Secure Shell Protocol). When you connect via SSH, you authenticate using a private key file on your local machine. For more information, see "About SSH."
After you generate an SSH key pair, you must add the public key to GitHub.com to enable SSH access for your account.
必要な環境
Before adding a new SSH key to your account on GitHub.com, complete the following steps.
- Check for existing SSH keys. For more information, see "Checking for existing SSH keys."
- Generate a new SSH key and add it to your machine's SSH agent. 詳しい情報については、「新しい SSH キーを生成して ssh-agent に追加する」を参照してください。
Adding a new SSH key to your account
After adding a new SSH key to your account on GitHub.com, you can reconfigure any local repositories to use SSH. 詳しい情報についてはリモート URL の HTTPS から SSH への切り替えを参照してください。
Note: GitHub improved security by dropping older, insecure key types on March 15, 2022.
As of that date, DSA keys (ssh-dss
) are no longer supported. You cannot add new DSA keys to your personal account on GitHub.com.
RSA keys (ssh-rsa
) with a valid_after
before November 2, 2021 may continue to use any signature algorithm. RSA keys generated after that date must use a SHA-2 signature algorithm. Some older clients may need to be upgraded in order to use SHA-2 signatures.
-
SSH 公開鍵をクリップボードにコピーします。
SSH 公開鍵のファイル名がサンプルコードと異なる場合は、現在の設定に一致するようにファイル名を変更してください。 キーをコピーする際には、改行や空白を追加しないでください。
$ pbcopy < ~/.ssh/id_ed25519.pub # Copies the contents of the id_ed25519.pub file to your clipboard
ヒント:
pbcopy
がうまく動作しない場合は、隠れフォルダ.ssh
にアクセスし、使い慣れたテキストエディタでこのファイルを開き、クリップボードにコピーしてください。 -
任意のページの右上で、プロフィール画像をクリックし、続いてSettings(設定)をクリックしてください。
-
In the "Access" section of the sidebar, click SSH and GPG keys.
-
[New SSH key] または [Add SSH key] をクリックします。
-
[Title] フィールドで、新しいキーを説明するラベルを追加します。 たとえば、個人のMacを使っているなら、このキーを「Personal MacBook Air」とすることができるでしょう。
-
キーを [Key] フィールドに貼り付けます。
-
[Add SSH key] をクリックしてください。
-
If prompted, confirm access to your account on GitHub. For more information, see "Sudo mode."
-
SSH 公開鍵をクリップボードにコピーします。
SSH 公開鍵のファイル名がサンプルコードと異なる場合は、現在の設定に一致するようにファイル名を変更してください。 キーをコピーする際には、改行や空白を追加しないでください。
$ clip < ~/.ssh/id_ed25519.pub # Copies the contents of the id_ed25519.pub file to your clipboard
ヒント:
clip
がうまく動作しない場合は、隠しフォルダ.ssh
にアクセスし、使い慣れたテキストエディタでこのファイルを開き、クリップボードにコピーしてください。 -
任意のページの右上で、プロフィール画像をクリックし、続いてSettings(設定)をクリックしてください。
-
In the "Access" section of the sidebar, click SSH and GPG keys.
-
[New SSH key] または [Add SSH key] をクリックします。
-
[Title] フィールドで、新しいキーを説明するラベルを追加します。 たとえば、個人のMacを使っているなら、このキーを「Personal MacBook Air」とすることができるでしょう。
-
キーを [Key] フィールドに貼り付けます。
-
[Add SSH key] をクリックしてください。
-
If prompted, confirm access to your account on GitHub. For more information, see "Sudo mode."
-
SSH 公開鍵をクリップボードにコピーします。
SSH 公開鍵のファイル名がサンプルコードと異なる場合は、現在の設定に一致するようにファイル名を変更してください。 キーをコピーする際には、改行や空白を追加しないでください。
$ cat ~/.ssh/id_ed25519.pub # Then select and copy the contents of the id_ed25519.pub file # displayed in the terminal to your clipboard
Tip: Alternatively, you can locate the hidden
.ssh
folder, open the file in your favorite text editor, and copy it to your clipboard. -
任意のページの右上で、プロフィール画像をクリックし、続いてSettings(設定)をクリックしてください。
-
In the "Access" section of the sidebar, click SSH and GPG keys.
-
[New SSH key] または [Add SSH key] をクリックします。
-
[Title] フィールドで、新しいキーを説明するラベルを追加します。 たとえば、個人のMacを使っているなら、このキーを「Personal MacBook Air」とすることができるでしょう。
-
キーを [Key] フィールドに貼り付けます。
-
[Add SSH key] をクリックしてください。
-
If prompted, confirm access to your account on GitHub. For more information, see "Sudo mode."
GitHub CLIについてさらに学ぶには、「GitHub CLIについて」を参照してください。
Before you can use the GitHub CLI to add an SSH key to your account, you must authenticate to the GitHub CLI. For more information, see gh auth login
in the GitHub CLI documentation.
To add an SSH key to your GitHub account, use the ssh-key add
subcommand, specifying your public key.
gh ssh-key add key-file
To include a title for the new key, use the -t
or --title
flag.
gh ssh-key add key-file --title "personal laptop"
If you generated your SSH key by following the instructions in "Generating a new SSH key", you can add the key to your account with this command.
gh ssh-key add ~/.ssh/id_ed25519.pub