How Do I Connect To A Github Repository Using SSH ?

Solution Verified - Updated -

Environment

Ansible Tower/Engine

Issue

Setup SSH keys for use with GitHub.

Resolution

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username and personal access token at each visit. For that you need to follow below steps:

  1. Generate a new SSH key:

    ssh-keygen -t rsa -C "your_email@example.com"
    
  2. Adding a new SSH key to your GitHub account settings :

    Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your 
    GitHub account Settings
    
  3. Test SSH key:

    $ ssh -T git@github.com
    Hi developius! You've successfully authenticated, but GitHub does not provide shell access.
    
  4. Change directory into the local clone of your repository (if you're not already there) and run:

    git remote set-url origin git@github.com:username/your-repository.git
    
  5. Now try editing a file (try the README) and then do:

    $ git commit -am "Update README.md"
    $ git push
    

    You should not be asked for a username or password. If it works, your SSH key is correctly configured.

  • Component
  • git

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments