2FA give problems when pushing to GitHub

前端 未结 5 1622
傲寒
傲寒 2020-12-15 06:10

I\'ve clone a project on GitHub on my Raspberry Pi, create a new branch and push everything to the repository. For this I needed next commands:

git clone htt         


        
相关标签:
5条回答
  • 2020-12-15 06:29

    with 2FA you have to create a personal access token to use as a password when authenticating to GitHub on the command line with HTTPS URLs: https://help.github.com/articles/which-remote-url-should-i-use/#when-2fa-is-enabled

    or you can clone with ssh https://help.github.com/articles/which-remote-url-should-i-use/#cloning-with-ssh-urls (may also be useful: https://help.github.com/articles/generating-an-ssh-key/)

    0 讨论(0)
  • 2020-12-15 06:36

    You can either use HTTPS URL of the repo or SSH URL of the for pushing, pulling, cloning or fetching operations from your local server after you have added 2FA on your GitHub account. The difference will be:

    While using the HTTPS URL: Now for pushing, pulling, fetching or cloning operations, you have to generate a Personal access token form your GitHub account and that will be used as password whenever you are asked for a password. You have to keep the token secure.

    Visit: Creating a personal access token for the command line

    While using the SSH URL: For Pushing, Pulling, Fetching or Cloning through SSH URL of the repo, you need to have a private key and public pair set up for your account. This will take a little amount of time but once you are done setting your private and public key, you will never be prompted for a username or password because now GitHub knows your identity.

    For creating the private key and public key pair, read: Connecting to GitHub with SSH

    Difference between using HTTPS URL and SSH URL:

    While HTTPS is not blocked by any firewall or by any network, SSH may be blocked sometimes and you may not be able to use it, however, it happens rarely. While using HTTPS, as said you will be asked ofter for username and password(which is your personal access token), you can cache it using credential.helper but it will save as a plain text.

    While for SSH, you can generate a passphrase for your private key, How do I add a password to an OpenSSH private key that was generated without a password?

    Now your private key will be secured but whenever you'll Push, Pull, Clone or Fetch, the passphrase will be asked each time. To avoid that you can use an SSH agent, SSH Key - Still asking for password and passphrase

    0 讨论(0)
  • 2020-12-15 06:41

    If you've cloned over https and want to keep using that, for whatever reason, you can edit .git/config to include the personal access token generated per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line.

    A sample .git/config entry:

    [remote "<YOUR-REMOTE-NAME>"]
        url = https://<YOUR-USERNAME>:<YOUR-TOKEN>@github.com/<etc your repo url>
    

    This is putting your token key in this plain text file on your machine, which is bad, but if you need a quick hack to get things going, it works.

    Cheers!

    0 讨论(0)
  • 2020-12-15 06:49

    with 2FA you need to generate personal access token while pushing the code. That personal token will be used as a password while pushing the code to Github. You can see that how to create the personal access token from https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line. It will be used when you have clone the repo with http url. It will be working for all the repositories.

    If you have cloned the through SSH then you can push your changing very easily without any changes in normal behavior after enabling the 2F authentication. For this you use SSH key passphrase as a password. First it requires you to create SSH key against your repository. You can generate SSH key from https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent It will be working only single repository only for that specific repsority again which this SSH key has been generated.

    0 讨论(0)
  • 2020-12-15 06:50

    You have to generate an access token and use the access token instead the password. For example:

    $ git clone https://github.com/username/repo.git
    Username: your_username
    Password: your_token
    

    Doc: https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line

    0 讨论(0)
提交回复
热议问题