ETC

[Git] Git push할 때 Authentication failed 문제 해결

HEY__ 2024. 11. 11. 16:28
728x90

이 글은 공부를 하면서 알게 된 내용들을 기록하는 글 입니다. 오류나 고쳐야 할 사항들이 있다면 지적 부탁드립니다!

✅ GitHub Desktop & Git terminal push할 때 오류 발생

Github Desktop push 시도 시 오류 발생

 

프로젝트 개발할 때 GitHub Desktop을 주로 사용하여 코드를 원격저장소에 올리는데, 갑자기 위와 같이 `Authentication failed` 오류가 발생했습니다.

 

혹시 Github Desktop에 문제가 있나 싶어, git terminal을 통해 push를 시도해도 밑과 같이 `Invalid username or password` 오류가 계속 발생했습니다.

❯ git push origin feat/266-test-account
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/TeamTheGenius/TeamTheGenius_Server/'

 

 

구글링을 통해 Github 재로그인도 해보고, `git config --global --unset`, `git config` 명령어를 통해 자격 증명을 다시 설정해줘도 같은 현상이 계속 반복되었습니다 :(

 

바로 어제까지만해도 아무런 이상이 없었는데 갑자기 오류가 발생한 것이 아무리 생각해도 이상해 기억을 다시 더듬어보니...

메일로 GitHub의 `Personal Access Token(이하 PAT)`이 만료되었으니 업데이트하라는 메일을 받았고, `PAT`를 갱신한 기억이 났습니다.

 

1️⃣ GitHub 홈페이지를 통해 PAT를 갱신했고, 2️⃣ 권한 문제로 push가 되지 않는다!! 면 다음와 같은 명령어를 통해 해결할 수 있습니다 :)

 

 


✅ git remote set-url origin

❯ git remote -v
origin	https://SSung023:{expired PAT}@github.com/TeamTheGenius/TeamTheGenius_Server (fetch)
origin	https://SSung023:{expired PAT}@github.com/TeamTheGenius/TeamTheGenius_Server (push)

❯ git remote set-url origin https://SSung023:{valid PAT}@github.com/TeamTheGenius/TeamTheGenius_Server.git

❯ git remote -v
origin	https://SSung023:{valid PAT}@github.com/TeamTheGenius/TeamTheGenius_Server.git (fetch)
origin	https://SSung023:{valid PAT}@github.com/TeamTheGenius/TeamTheGenius_Server.git (push)

 

 

 

1️⃣ `git remote -v`를 통해 등록된 `PAT` 확인하기

❯ git remote -v
origin	https://SSung023:{expired PAT}@github.com/TeamTheGenius/TeamTheGenius_Server (fetch)
origin	https://SSung023:{expired PAT}@github.com/TeamTheGenius/TeamTheGenius_Server (push)

`git remote -v` 명령어를 통해 등록된 Personal Access Token을 확인할 수 있습니다.

만일 `PAT` 관련 문제라면, Github Settings에서 새롭게 발급받은 PAT와 비교했을 때 다른 값을 가지고 있을 것입니다.

 

 

2️⃣ `git remote set-url` 명령어를 통해 유효한 `PAT` 적용하기

// git remote set-url origin https://{Github ID}:{valid PAT}@github.com/{적용하고자하는 repository}.git
❯ git remote set-url origin https://SSung023:{valid PAT}@github.com/TeamTheGenius/TeamTheGenius_Server.git

{valid PAT}로 설정한 곳에 새롭게 발급받은 PAT를 입력한 명령어를 작성합니다.

 

 

3️⃣ `git remote -v`를 통해 적용되었는지 확인하기

❯ git remote -v
origin	https://SSung023:{valid PAT}@github.com/TeamTheGenius/TeamTheGenius_Server.git (fetch)
origin	https://SSung023:{valid PAT}@github.com/TeamTheGenius/TeamTheGenius_Server.git (push)

`git remote -v` 명령어를 통해 확인해보면 새롭게 발급받은 PAT가 적용되어 있음을 확인할 수 있습니다.

 

이후 `git push origin` 요청을 하면 정상적으로 푸시가 됨을 확인할 수 있습니다.

728x90