Add SSH to Github
Table of Contents
- Generate a new SSH key pair
- If you wanna change current remote url to ssh url
- If you use ssh key with passphrase, you can use ssh-agent to save your passphrase
Generate a new SSH key pair
- Open a terminal window.
- Generate a new SSH key pair by running the following command:
ssh-keygen -t rsa
This will create two files:
* `id_rsa`: This is your private key. Keep it safe!
* `id_rsa.pub`: This is your public key. You can share this with others.
- Copy the contents of your public key to the clipboard by running the following command:
cat ~/.ssh/id_rsa.pub
or automatically copy to clipboard
pbcopy < ~/.ssh/id_rsa.pub
- Go to your GitHub account settings.
- Click on SSH and GPG keys.
- Click on New SSH key.
- Paste your public key into the Key field.
- Click Add SSH key.
- You're done! You can now clone your repositories using the SSH URL.
If you wanna change current remote url to ssh url
- Remove current remote url
git remote rm origin
- Add new remote url
git remote add origin your_new_remote_url
If you use ssh key with passphrase, you can use ssh-agent to save your passphrase
- Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
- Add your SSH private key to the ssh-agent.
ssh-add ~/.ssh/id_rsa
- Now you can push your code without typing your passphrase every time.