You can use SSH keys for the 2-Factor-Identification within GitHub. Here are the steps to follow to set your SSH keys:

  1. 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
  2. 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:
  3. For ease of usage, in your machine you can add the following lines to the file ~/.ssh/config (you might need to create it):
     IdentityFile ~/.ssh/laptop_git
     User git

Then, you are ready to clone repositories and interact with GitHub using SSH keys.