git push 인증오류시 해결방법

git push를 하다가 아래와 같은 인증오류를 보았다면, github 비밀번호를 갱신할 때가 된것이다. github 사이트 로그인할 때 사용하는 계정의 비밀번호는 아니고, 특정권한을 가진 토큰정보를 갱신하다고 보면된다.

> git push
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/*****/****-app.git/'

사실 이렇게 오류가 나기전에 본인 이메일계정으로 아래와 같이 발송해준다. 친절히 url 주소까지 알려주면서, 접속해서 갱신하라고 알려준다.

[GitHub] Your personal access token (classic) is about to expire

Hi @user,

We noticed your personal access token (classic) "repo" with repo scope will expire in about 17 hours.

If this token is still needed, visit https://github.com/settings/tokens/101******023/regenerate to generate an equivalent.

If you run into problems, please contact support by visiting https://github.com/contact?tags=dotcom-accounts

Thanks,
The GitHub Team

클릭하면 아래 페이지로 이동된다. 놀라지말고, 3달정도 선택하고 “Regenerate token” 버튼을 클릭한다.

그 다음에, 적절한 권한을 부여하도록 한다. 그냥 repo 하위의 권한들 정도로 충분해서 이것만 선택했다.

그러면 이제 비밀번호(토큰)이 만들어지는데, 이건 한번만 보여지니 어딘가 복사를 해놓자

자 이제 모든게 끝났다. 다음 만료일은 5월이다. 다시 커멘트창에 돌아가서, git push 하면, 아이디/비밀번호를 재입력하라고 나올텐데, 방금 생성된 토큰을 복사해서 붙여넣으면 잘 push 된다.

혹시 아래와 같이 매번 비밀번호를 물어본다면,

$ git push
Username for 'https://github.com': yourname
Password for 'https://yourname@github.com': 
Everything up-to-date

이 명령어를 사용하면 한번 입력후 더이상 비번과 유저명을 물어보지 않게 된다. 개인PC에만 사용하길 권장한다.

$ git config --global credential.helper store
git 

더 보면 좋을 글들