You can use SSH keys for the 2-Factor-Identification within GitHub. Here are the steps to follow to set your SSH keys:
- Generate the pair of public and private SSH keys. If you want to generate a key in your laptop to connect to git, that you would like to name
laptop_git
, you should type the following command and enter a passphrase when prompted:ssh-keygen -t rsa -b 4096 -f ~/.ssh/laptop_git
- In GitHub go to your profile -> Settings -> SSH and GPG keys -> click the green button with ‘‘New SSH key’’ and copy the public part of the SSH key:
laptop_git.pub
- For ease of usage, in your machine you can add the following lines to the file
~/.ssh/config
(you might need to create it):Host github.com HostName github.com IdentityFile ~/.ssh/laptop_git User git
Then, you are ready to clone repositories and interact with GitHub using SSH keys.