Logo

dev-resources.site

for different kinds of informations.

How to Configure GitHub Authentication Using SSH Certificates

Published at
12/27/2024
Categories
github
ssh
authentication
devops
Author
jajera
Categories
4 categories in total
github
open
ssh
open
authentication
open
devops
open
Author
6 person written this
jajera
open
How to Configure GitHub Authentication Using SSH Certificates

How to Configure GitHub Authentication Using SSH Certificates

Using SSH certificates to authenticate with GitHub is a secure and efficient way to manage your repositories. This guide will walk you through the process step by step.


1. Generate an SSH Key Pair

First, create a new SSH key pair or use an existing one.

Run the following command:

ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519_github -C "ssh key for github"
Enter fullscreen mode Exit fullscreen mode
  • -o: Ensures the private key file is saved in the new OpenSSH format for improved security.
  • -a 100: Specifies the number of rounds for the key derivation function, enhancing brute-force resistance.
  • Enter a passphrase (optional but recommended for added security).

2. Add the SSH Key to Your SSH Agent

Next, ensure your SSH key is available to the SSH agent.

Start the SSH agent:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Add your private key:

ssh-add ~/.ssh/id_ed25519_github
Enter fullscreen mode Exit fullscreen mode

3. Add the Public Key to Your GitHub Account

Now, link your public SSH key to your GitHub account:

  1. Copy the contents of your public key:
   cat ~/.ssh/id_ed25519_github.pub
Enter fullscreen mode Exit fullscreen mode

Note: Ensure that you only share the public key file (e.g., id_ed25519_github.pub) and never share your private key file (e.g., id_ed25519_github).

  1. Add the key to GitHub:
    • Open GitHub SSH Settings.
    • Click New SSH key.
    • Paste your public key into the key field.
    • Give it a descriptive title and save it.

4. Configure SSH for GitHub

To ensure GitHub uses the correct SSH key, configure your SSH settings:

Edit (or create) the ~/.ssh/config file:

nano ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Add the following configuration:

Host github.com
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519_github
  IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

Note: This ensures that only the specified identity file is used, which is crucial in environments with multiple SSH keys to avoid authentication errors.

Save and exit the file.


5. Test Your SSH Connection

Verify that GitHub recognizes your SSH setup by running:

ssh -T [email protected]
Enter fullscreen mode Exit fullscreen mode

If everything is set up correctly, you should see a success message:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Note: If this step fails, ensure the following:

  • Verify that the SSH key has the correct permissions by running chmod 600 ~/.ssh/id_ed25519_github.
  • Confirm that the public key is added to your GitHub account.
  • Check that the ~/.ssh/config file is properly configured.

6. Use SSH for GitHub Repositories

Finally, use SSH URLs for GitHub repositories:

  • Clone a repository using SSH:
  git clone [email protected]:username/repository.git
Enter fullscreen mode Exit fullscreen mode
  • Update an existing repository's remote URL to use SSH:
  git remote set-url origin [email protected]:username/repository.git
Enter fullscreen mode Exit fullscreen mode

Tip: To confirm that the remote URL has been updated successfully, run:

  git remote -v
Enter fullscreen mode Exit fullscreen mode

Conclusion

With this setup, you've configured GitHub to authenticate using SSH certificates, providing a secure and efficient method for managing your repositories. Let me know in the comments if you have any questions or tips to share!


ssh Article's
30 articles in total
Favicon
How to Set Up Key-Based and Password-Based SSH for a Newly Created User on an EC2 Instance
Favicon
SSH Keys | Change the label of the public key
Favicon
让安卓手机不再吃灰:在安卓手机上搭建 Rust 开发环境
Favicon
SSH port forwarding from within code
Favicon
Mastering Ansible on macOS A Step by Step Guide
Favicon
kkTerminal —— A terminal for Web SSH connection
Favicon
Set Up SSH in 1 Minute Setup Like a Pro (With Some Fun Along the Way)
Favicon
How to Configure GitHub Authentication Using SSH Certificates
Favicon
Understanding SSH: Secure Shell Protocol
Favicon
Check gitlab ssh key auth
Favicon
How I Secured Port 22
Favicon
SSH port forwarding from within Raku code
Favicon
Changing an established SSH connection without disconnecting
Favicon
SSH port forwarding from within Rust code
Favicon
Configure SSH Passwordless Login from Windows to Linux
Favicon
Push to multiple GitHub accounts!
Favicon
Access to Google Cloud Virtual Machine through SSH
Favicon
Large file transfer from VPS to local machine
Favicon
Secure Your Ubuntu VPS: Restrict SSH Access to a Specific IP
Favicon
Accessing Remote Databases Without VPN Using SSH Tunnels
Favicon
Carla Simulator 1 : How to Set Up CARLA Simulator 🏎️🔥
Favicon
Getting Started with Oysape: Exploring Task and Pipeline
Favicon
Increase Debian based Linux VPS server’s security
Favicon
Splunk - SSH Dashboard Creation
Favicon
Debugging SSH connections: A Comprehensive Guide
Favicon
Understanding SSH Key Pairs: A Developer's Guide
Favicon
SSH Config File - Forgotten Gem
Favicon
SSH kalitini Github.com'ga qo'shish
Favicon
Using SSH to Connect Local Git to Remote Repositories
Favicon
Quickly and Easily Manage Multiple SSH and GPG Keys Across Git Repositories

Featured ones: