Program Tip

2FA 활성화 후 Git 인증 실패

programtip 2020. 10. 16. 08:00
반응형

2FA 활성화 후 Git 인증 실패


방금 2FA를 활성화하고 (다른 변경 사항을 생각할 수 없음) git이 내 사용자 이름과 암호를 요청했습니다. 둘 다 제공했지만 "틀 렸습니다". 여기에서 많은 솔루션을 시도했습니다. Git 푸시에는 사용자 이름과 암호가 필요 하지만 작동하지 않았습니다. 특히 https에서 ssh로 전환 할 때 ssh 키는

권한이 거부되었습니다 (공개 키). 치명적 : 원격 저장소에서 읽을 수 없습니다.

$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'https://github.com': **********
Password for 'https://mlbileschi@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/mlbileschi/scala.git/'

팁이 있습니까?


액세스 토큰을 생성해야합니다. 설정 페이지 로 이동하여 만들 수 있습니다 .

여기에 이미지 설명 입력

이 액세스 토큰을 명령 줄에서 암호로 사용합니다.


종단 간 솔루션에는 3 단계가 필요합니다.

  1. Gergo Erdosi에 대한 명성. 그의 대답은 대체로 옳습니다. Github가 해당 설정 페이지를 변경한다는 것입니다. 2016 년 말 부터 개인 액세스 토큰 페이지 에서 액세스 토큰생성 해야 합니다 .

    여기에 이미지 설명 입력

    이 액세스 토큰을 명령 줄에서 암호로 사용합니다.

  2. 프로젝트 원격 URL에 포함하여 사용자 이름을 유지할 수 있습니다. 이를 수행하는 방법 중 하나는 행을 다음 형식으로 .git/config수정 하도록 편집하는 것 url입니다.

    url = https://YOUR_USERNAME_HERE@github.com/owner/repo.git

  3. 한 번만 실행하여 암호를 유지할 수 있습니다.

    $ git config credential.helper store

    그런 다음 향후 git 암호는 ~ / .git-credentials 형식을 사용하여 일반 텍스트로 저장됩니다 https://user:PlaintextPassword@example.com.

    일반 텍스트로 암호를 저장하는 것은 일반적으로 보안 위험으로 간주됩니다. 그러나이 2FA의 경우 자격 증명은 실제 암호가 아니라 임의로 생성 된 문자열입니다. 따라서 ssh 개인 키 를 암호가없는 ssh 개인 키 를 사용 하는 것만 큼 ​​안전 합니다. 주의 :이 컴퓨터에서 2FA없이 다른 git 계정을 사용하는 경우 실제 비밀번호도 일반 텍스트로 저장됩니다.

추신 : 또는 암호로 보호 된 ssh 개인 키를 사용하여 ssh 기반 로그인을 사용하도록 선택할 수 있습니다. 이는 더 안전하고 덜 편리하지만이 답변의 범위를 벗어납니다.


비슷한 문제가있었습니다. 내 사용자 이름을 포함하도록 git 명령에 사용 된 URL을 변경해야했습니다.

git push https://YOUR_USERNAME_HERE@github.com/mlbileschi/scala.git

Then when it asks for PW use the access token you created from following the instructions in Gergo Erdosi's answer.


On linux, you can authenticate your GitHub identity using an SSH key.

1) Generating a new SSH key (source)

Open terminal.

Paste the text below, substituting in your GitHub email address.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This creates a new ssh key, using the provided email as a label.


2) Linking the key to your GitHub account

Open terminal and copy the generated public key

cat ~/.ssh/id_rsa.pub

Should output somthing as

ssh-rsa AAAAB3NzaC1y ... mKAKw== your_email@example.com

Navigate to https://github.com/settings/keys and click New SSH Key, give it a Title and copy-paste the public key.

여기에 이미지 설명 입력


3) Change git origin from https:// to ssh

Open terminal, cd to your repository location and type

git remote set-url origin git@github.com:<github username>/<repository name>

This worked for me:

  • Go to [your-git-repo]/.git/config

  • 에서 [remote "origin"]변경 URL자식에 대한 프로토콜 HTTP에서 키를 누릅니다.

의 값 urlhttps://github.com/ .git 이면 다음으로 변경하십시오.git@github.com:<repo-url>.git


이미 ssh 키를 사용중인 경우 2FA를 활성화 한 후 SSH를 사용하여 원격 읽기 / 쓰기를 강제합니다. 기존 SSH 키 쌍을 계속 사용하는 대신 개인 토큰을 추가 할 필요가 없습니다.

원격 URL을 HTTPS에서 SSH로 변경하기 만하면됩니다.

git remote set-url origin git@github.com:<github-username>/<repo-name>

참고 URL : https://stackoverflow.com/questions/25550481/git-authentication-fails-after-enabling-2fa

반응형