GitLab 비밀번호 변경 후 토큰 재설정 트러블슈팅 - 이참에 토큰 셋팅 가이드 정리

728x90

GitLab 비밀번호 변경 후 토큰 재설정 트러블슈팅

상황

GitLab 계정 비밀번호가 변경된 뒤 git fetch가 멈추거나 인증 실패가 발생했다.

현재 저장소 원격 주소:

origin  http://gitlab.[:url]

실제로 확인한 에러:

HTTP/1.1 401 Unauthorized
fatal: could not read Username for 'http://gitlab.[:url]'
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password.

확인한 내용

git fetch가 멈춘 것처럼 보였지만, 실제로는 인증 입력을 기다리는 상태였다.

아래 명령으로 확인했다.

GIT_TERMINAL_PROMPT=0 git fetch --verbose origin

결과:

fatal: could not read Username for 'http://gitlab.[:url]: terminal prompts disabled

새 비밀번호로 직접 인증도 확인했지만 GitLab에서 거부했다.

remote: HTTP Basic: Access denied.

따라서 GitLab 계정 비밀번호가 아니라 Personal Access Token을 사용해야 하는 상황으로 판단했다.

HTTPS 확인

처음에는 원격 주소를 https://로 바꾸는 방법도 확인했지만, 현재 환경에서는 HTTPS 연결이 실패했다.

OpenSSL SSL_connect: SSL_ERROR_SYSCALL

그래서 원격 주소는 기존 http://를 유지하고, 토큰 인증만 다시 설정한다.

토큰 생성

GitLab 웹에서 Personal Access Token을 생성한다.

  1. http://gitlab.[:url] 접속
  2. 로그인
  3. 프로필 메뉴 진입
  4. Preferences 또는 Edit profile 이동
  5. Access Tokens 또는 Personal access tokens 선택
  6. 토큰 이름 입력
  7. 만료일 설정
  8. 권한 선택

필요 권한:

read_repository   fetch, pull
write_repository  push

생성된 토큰은 다시 볼 수 없으므로 바로 저장한다.

기존 인증 정보 삭제

git credential-wincred erase만 실행하면 멈춘 것처럼 보인다.

이 명령은 입력을 기다리는 방식이라, 아래처럼 한 번에 넘겨서 삭제한다.

printf "protocol=http\nhost=gitlab.prd.console.trombone.okestro.cloud\nusername=hs.kwan\n\n" | git credential-wincred erase

출력이 없어도 정상이다.

Credential Helper 설정

이 저장소에서는 wincred를 사용하도록 설정했다.

git config --local --unset-all credential.helper 2>/dev/null || true
git config --local --add credential.helper ""
git config --local --add credential.helper wincred

확인:

git config --show-origin --get-all credential.helper

.git/config에 아래처럼 보이면 된다.

file:.git/config
file:.git/config wincred

토큰으로 fetch

다시 fetch를 실행한다.

git fetch

VSCode 상단에 입력창이 나오면 아래처럼 입력한다.

Username: hs.kwan
Password: 생성한 GitLab Personal Access Token

Password에는 GitLab 계정 비밀번호가 아니라 토큰을 넣는다.

728x90