Generate a New SSH Key #
Run the following command to generate a new SSH key:
ssh-keygen -t ed25519 -C "[email protected]"
- Replace
[email protected]
with the email address you use for your Git account. - The
-t ed25519
flag specifies the type of key to create (Ed25519 is recommended for new keys).
Specify a Filename for the Key #
You'll be prompted to enter a filename to save the key. To create a key specifically for Git, type /root/.ssh/id_ed25519_git
:
Enter file in which to save the key (/root/.ssh/id_ed25519): /root/.ssh/id_ed25519_git
Do not Set a Passphrase! (For deploy keys this should be skipped)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Add your SSH key to Git settings #
Open Git config: ~/.ssh/config
nano ~/.ssh/config
Add the following part:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_git
IdentitiesOnly yes
Add the SSH Key to Your Git Hosting Service #
Copy the SSH key to your clipboard:
cat ~/.ssh/id_ed25519_git.pub
Add the SSH Key as a Deploy Key to your Repository
- Go to your repository on GitHub.
- Navigate to "Settings" > "Deploy keys" (e.g. https://github.com/PROFILE/REPOSITORY/settings/keys)
- Click "Add deploy key", give it a title, paste the SSH key. You might need to verify your identity e.g. with 2FA verification.
- If you succeed you will see something like this:
For further an in-depth extensive guide visit Docs.Github.com.
Clone your repository #
Optional: check SSH connection:
ssh -T [email protected]
If set up correctly you should see something like this:
Hi USER_NAME/PROJECT! You've successfully authenticated, but GitHub does not provide shell access.
Clone your Repository:
git clone [email protected]:USER_NAME/PROJECT.git
NOTE: USER_NAME
may differ from your GitHub username, especially if you're acting as a member of an organization. In such cases, you might need to use the organization's username instead of your own.
Troubleshoot #
By default Github show your HTTPS link to your repo, be sure that you are using the SSH version: