Access GitHub using SSH
If you want to use SSH to connect to GitHub, you can follow the steps below:
- Generate a new SSH key:
ssh-keygen
You will see there is a new file named id_rsa
and id_rsa.pub
in the ~/.ssh
directory.
Add the SSH key to the ssh-agent:
Get on to github.com and click on your profile picture on the top right corner. Then click on
Settings
Click on
SSH and GPG keys
on the left sidebarClick on
New SSH key
buttonEnter a title for the SSH key
Copy the contents of the
id_rsa.pub
file and paste it into theKey
fieldClick on
Add SSH key
button
Set up the SSH config file:
Create a new file named
config
in the~/.ssh
directoryAdd the following content to the
config
file:
~/.ssh/configHost github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa- Save the file
Ready to go now:
- Clone the repository using SSH:
git clone git@github.com:<github-account>/<repo-name>.git
- Push the changes to the remote repository:
git push git@github.com:<github-account>/<repo-name>.git
- Pull the changes from the remote repository:
git pull git@github.com:<github-account>/<repo-name>.git