PAT란
- Personal Access Token의 약어로,
- 기존의 GitHub 계정 password 대신에 사용되는 긴 문자열 Token임.
HTTPS 프로토콜로 git push / pull 할 때,
password 자리에 PAT를 넣으면 인증이 됨.
현재 보안 문제로 password 를 통한 push / pull 은 안되는 상황이므로 이를 대체하는 방법임.
비밀키 / 공개키 기반의 authentication 을 권장하나...
Token이 직관적인 측면이 있어서 password 처럼 이용하는 이들도 있음
키 관련해서 다음을 참고:
PAT 발급받기
GitHub는 PAT를 다음의 두가지 종류로 제공함:
- Fine-grained Token
- Classic Token
Fine-grained PAT의 경우, 대상 저장소 및 허용권한을 매우 세밀하게 조정이 가능해서 보다 권장됨
Classic PAT의 경우는 현재 호환성을 위해 남아있는 상황으로 가급적이면 Fine-grained PAT를 사용하는게 좋음
Fine-grained PAT의 발급은 다음과 같음.
우선 GitHub의 Settings 를 클릭

왼쪽 사이드바의 아래에 있는 Developer settings 클릭

Personal access tokens 에 있는 Fine-grained tokens를 클릭하면 Generate new token 버튼이 보임.
이를 클릭.

우선 Token의 이름을 짓고, 사용 용도를 description에 기재

이후 Expiration Date (기본으로 30일) 를 정하고, 대상으로할 repository를 선택.

아래의 Permissions 에서 필요한 최소권한을 주기 위해 Add permissions 를 클릭하고 보이는 여러 권한 중에서 Content를 선

이후 Content에 대해 Read and wirte 권한을 부여하면 repository를 수정할 수 있음

이 후 아래의 Generate token 버튼을 클릭

이후 confirm을 위한 창이 뜸. 역시 Generate token을 클릭

이후 생성된 Token을 확인할 수 있음

상당히 긴 문자열(붉은 색 박스)이기 때문에 외우기 어려워서 자동으로 입력해주는 Credential Helper를 이용하는 게 일반적임.
(이후로는 확인할 수 없으므로 복사해놔야함)
Credential Helper 사용하기:
Git core는 인증 정보를 직접 저장하지 않으며 대신 credential helper라는 외부 프로그램을 호출하여
인증 정보에 대한 “저장(store)”, “조회(get)”, “삭제(erase)”를 위임함.
대표적인 Credential Helper로는 다음이 있음:
| helper | 저장 위치 |
cache |
RAM (메모리, cache-daemon) |
store |
평문 파일 (~/.git-credentials) |
manager |
Windows Credential Manager (GCM) |
osxkeychain |
macOS Keychain |
단, 공용장비에서 사용할 경우 위험하므로
- in-memory cache 방식으로 동작하면서
- credential TTL (Time To Live)를 second단위로 할당해 주는 게 좋음.
다음은 현재 local repository (.git/config)에서 앞서 만든 Token을 3시간(=10,800초) 정도 메모리의 캐시로 저장하여 사용하는 명령어임.
git config credential.helper "cache --timeout=10800"
로컬 전체의 repositories (~/.gitconfig)에서 쓰려면 --global 옵션을 추가해주면 됨.
git config --global credential.helper "cache --timeout=10800"
이를 사용하면 한번 인증한 경우 3시간 동안 추가 인증없이 사용가능함.
참고로, 여러 PAT를 사용해야 하는 경우가 많으므로 다음도 설정해 주는 것이 좋음:
git config --global credential.useHttpPath true
- credential 를 찾을 때, protocol 과 host 만 사용하는게 기본으로, 위의 설정이 false임.
- true로 해 줄 경우, portocol + host + path 를 lookup key로 삼아서 credential 이 적용됨
- PAT의 경우 같은 host에서도 각 repository별로 다른 경우가 많으므로 이를 true로 해주는게 좋음.
- 단, 공용장비에선 굳이 여러 repository를 건드리는 건 권하지 않음.
참고: Windows의 GCM 사용시 유의할 점.
Windows의 GCM(Git Credential Manager)은 wincerdman(Windows Credential Manager)인데
wincerdman은 앞서 명령어의 in-memory chache 방식을 지원하지 않는다는 문제점이 있음.
- Windows GCM의 기본 동작은 timeout 기반 메모리 캐시가 아니라
- Windows Credential Manager에 인증 정보를 저장하는 방식임.
- 따라서 저장된 인증 정보는 timeout이 지나도 자동으로 제거되지 않기 때문에,
- 계정 변경이나 토큰 변경 시 수동 삭제가 필요할 수 있음.
참고로 Windows 의 GCM 을 사용할 때 다음이 기본값임:
git config --global credential.helper manager
git config --global credential.credentialStore wincredman
git config --global credential.useHttpPath false
- Windows에서 GCM 사용을 하려면 첫번째 라인만 수행하면 됨.
- Windows에서 GCM의 기본 credential store는 wincredman 이라, 두번째 라인을 수행하지 않아도 됨.
- 기본적으로 credential.useHttpPath는 false 임.
- 이 경우 Git은 repository path가 아니라
- 주로 protocol, host, username 기준으로 credential 을 다르게 할당할 수 있음.
- 따라서 같은 host 인 경우 해당 host의 여러 repository가 같은 credential을 공유하게 됨.
다시 강조하지만, Window GCM 의 경우 PAT 는
- OS Credential Manager에 영구 저장되고
- timeout 기반 메모리 캐시 개념이 없음
같은 host에서 여러 계정이나 여러 repository별 credential을 구분해야 한다면 다음과 같이 바꾸는 것이 좋음:
git config --global credential.useHttpPath true
- 이렇게 하면 앞서 설명한대로 repository path까지 credential lookup에 포함되므로,
- 같은 host 안에서도 repository별로 credential을 분리해서 관리할 수 있다.
다음은 GCM을 직접 호출하여 자격증명(Credential)을 지우는 명령어임
git credential-manager erase
protocol=https
host=github.com
<empty line>
- 마지막에 empty new line 필요 (입력이 끝났음을 의미함) : <empty line> 이라고 입력하는 거 아님!!
- GCM이 관리하는 자격 증명 중 github.com 으로 관리되는 것들을 지움
path=ds31x/ds31x.github.io.git과 같이계정명/repository명을 추가하면 해당 repository만 삭제함. (추천).- 첫 라인을 git credential reject 이라고 해도 된다.
보다 Git에서 권하는 일반적인 명령어는 다음과 같음:
git credential reject
- 위 명령어는
- 전달한 credential description과 일치하는 저장된 자격 증명을
- helper에게 지우도록 요청하는 action
즉, 위 명령을 실행하면 stdin으로 삭제할 credential description (혹은 credential을 찾을 수 있는 조건)을 입력해야 함.
다음과 같이 입력하는 경우, 특정 respository에 해당하는 credential 만 삭제 가능함:
protocol=https
host=github.com
path=ds31x/ds31x.github.io.git
<empty new line)
Bash/Git 등과 같이 printf 를 지원하는 경우엔 다음의 방식도 가능:
printf "protocol=https\nhost=github.com\n\n" | git credential-manager erase
- 위의
printf는echo로 변경 가능하나, 이 경우 이식성이 떨어짐.
다음은 path를 지정한 방식임:
printf "protocol=https\nhost=github.com\npath=ORG/REPO.git\n\n" | git credential-manager erase
다음의 명령어로 GUI에서 확인 및 삭제도 가능함:
control keymgr.dll

Windows에서 Git Credential을 삭제하는 자세한 내용은 다음을 참고:
https://www.claudiuscoenen.de/2023/11/removing-git-credentials-windows/?utm_source=chatgpt.com
Removing Git Credentials (Windows) « Technology, Media and Life in General.
Removing Git Credentials (Windows) Posted by Claudius Coenen on November 7th, 2023 I found myself in an environment where I need to be able to log out users automatically. Erasing Stored Credentials Git on Windows uses the git credential manager by default
www.claudiuscoenen.de
같이보면 좋은 자료
2024.05.26 - [utils/git and github] - [Git] Tutorial: remote repository
[Git] Tutorial: remote repository
Remote Repository와 작업하기.이 문서는 Remote Repository와 작업하기 위한 기본적인 내용을 다룬다.Remote Repository는 github를 가정하며, 다음의 repository를 github에 처음 만들면 나오는 내용들을 살펴본다.
ds31x.tistory.com
'utils > git and github' 카테고리의 다른 글
| git init --bare : 편집가능한 소스 코드가 없는 (서버용) 저장소 만들기 (0) | 2025.12.01 |
|---|---|
| [Git] Relative Reference: caret and tilde + Reflog Reference (1) | 2025.07.24 |
| git difftool 과 git mergetool (1) | 2025.07.22 |
| SSH Agent 사용법 (2) | 2025.07.21 |
| 새로 remote 에 추가된 submodule 을 local 에 반영하기 (3) | 2025.07.11 |