카테고리 없음

Windows Terminal에서 Github PAT를 이용해 인증하기

constexpr 2023. 2. 7. 11:19
git: 'credential-cache' is not a git command. See 'git --help'.
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'XXX'

git push 명령을 통해 리포지토리에 밀어넣던 도중 이렇게 인증이 실패하는 경우가 생긴다.

보안을 위해 패스워드를 이용하는 방식의 인증은 이제 Github에서 지원하지 않게 되었고, 대신 Personal Access Token (PAT)를 이용해 인증하는 방식으로 바뀌게 되었다.

 

PAT를 발급받자

 

Github에 접속하여 Settings > Developer settings > Personal access tokens로 이동하자.

"Generate New token"버튼을 눌러 위와 같은 화면으로 이동할 수 있다.

Token name과 Expiration을 설정해주자. 만료 기한이 지나면 Regenerate를 해주어야하므로 넉넉하게 90일로 설정해주었다.

 

 아래의 Repository access로 해당 토큰의 리포지토리 접근 권한을 제어할 수 있고, 아래의 Permissions 섹션에서 동작에 대한 권한을 제어할 수 있다.

 그냥 코드 서밋하는 정도의 작업을 하는 개인 용도의 토큰이라면 All repositories에 code, issues, pull requests의 Read / Write 권한을 주면 된다.

 

 PAT가 발급 되면 이를 복사하고, Terminal에서 password대신 해당 토큰을 넣어주면 인증을 성공하게 된다.

 PAT를 발급 받고, 이를 저장하여 다음에 다시 인증을 하지 않길 원한다면,

$ git config --global credential.helper store

이렇게 git config를 설정한 뒤 PAT 인증을 실행해주면 된다.