First, make sure you have an SSH key on your local machine. You can check by running:
$ ls -al ~/.sshLook for files named id_rsa and id_rsa.pub. If they don’t exist, you’ll need to create a new SSH key.
If you don’t have an SSH key, generate one by running:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Press Enter to accept the default file location, and optionally, enter a passphrase.
Start the SSH agent:
$ eval "$(ssh-agent -s)"Add your SSH private key to the agent:
$ ssh-add ~/.ssh/id_rsaCopy the SSH key to your clipboard:
$ cat ~/.ssh/id_rsa.pub | xclip -selection clipboard Go to your GitHub SSH settings and click New SSH Key. Paste your key and give it a title.
Test your SSH connection to GitHub:
$ ssh -T git@github.comYou should see a message like: Hi username! You've successfully authenticated, but GitHub does not provide shell access..
Make sure your repository’s remote URL is set to use SSH, not HTTPS:
$ git remote -vIf it shows an HTTPS URL, you can change it to SSH:
$ git remote set-url origin git@github.com:username/repository.gitIf you prefer not to install xclip, you can also manually copy the SSH key by displaying it in the terminal and copying it: $ cat ~/.ssh/id_rsa.pub.