Skip to content

Accessing Private Repos using SSH

Sahaj Rana edited this page Dec 28, 2023 · 2 revisions

Generating a new SSH key

  1. If using Windows, open Git Bash, or if using macOS or Linux open the terminal.
  2. To generate keys, paste the below test, substituting in your GitHub email address.
$ ssh-keygen -t ed25519 -C "[email protected]"
  1. At the prompt, hit Enter
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

This will generate the public & private Keys for SSH authentication.

Adding your SSH key to the ssh-agent

  1. Start the ssh-agent
$ eval "$(ssh-agent -s)"
> Agent pid 59566
  1. Add your SSH private key to the ssh-agent
$ ssh-add ~/.ssh/id_ed25519

Adding a new SSH key to your GitHub account

  1. Open ~/.ssh/id_ed25519.pub file & copy the contents of a file.

  2. Open the Github profile on the web, and go to Settings>SSH and GPG keys.

    userbar-account-settings

  3. Click the New SSH key or Add SSH key.

ssh-add-ssh-key-with-auth

  1. In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal laptop, you might call this key "Personal laptop".
  2. Paste your key into the "Key" field.

ssh-key-paste-with-type

  1. Click Add SSH key.
  2. If prompted, confirm access to your account on GitHub.

Testing your SSH connection

  1. If using Windows, open Git Bash, or if using macOS or Linux open the terminal & enter the following:
$ ssh -T [email protected]
# Attempts to ssh to GitHub

You may see a warning like this:

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
  1. Verify the fingerprint by typing yes. It will prompt like

Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

For Windows OS,

If Adding ssh keys with ssh-add does not work. Follow the below 3rd procedure.

  1. Then add the created private-key in ssh_config file. It is located in C:\Program Files\Git\etc\ssh\ssh_config
...

Host github.com
    Hostname github.com
    IdentityFile ~/.ssh/my_ssh_key


Ready to make commits in private repos. Happy Coding!!

If not working, Retry or connect with experts.

  • [https://github.com/BlupGithub/custom_widgets](Custom Widgets)
Clone this wiki locally