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
SettingsClick on
SSH and GPG keyson the left sidebarClick on
New SSH keybuttonEnter a title for the SSH key
Copy the contents of the
id_rsa.pubfile and paste it into theKeyfieldClick on
Add SSH keybutton
Set up the SSH config file:
Create a new file named
configin the~/.sshdirectoryAdd the following content to the
configfile:
~/.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