본문 바로가기

인프라/MW

[GitLab] ID/PASSWORD STORE AFTER EASY GIT CLONE(SSH Key include Client between Server)

GitLab을 사용할 때마다, 매번 ID 와 PASSWORD를 쳐야하는 불편함이 있다.

이를 해결하기 위한 방법에 대해서 기재한다.

공식사이트를 참고하여 여러가지를 시도해 보았으나, 매우 난해하게 설명이 되어있어 한참을 시도하였으나 결과는 매우 간단하다.

결과만 기재하면, Client에서 생성 또는 기존에 사용되고있는 public키를 GitLab서버의 사용 계정에 ssh-key를 등재해주면 끝이다.


※ 사전준비작업
- Client로 사용될 Labtop/Server에, GitLab서버 호스트정보 등록
- vi /etc/hosts
  ex) 10.10.10.10 gitlab.com

1. Client에서 SSH-KEY를 복사
- if Key가 존재할 시, (rsa_key출력&복사하기)

cd; cat ~/.ssh/id_rsa.pub; 

- if Key가 존재하지 않을 시, (생성&rsa_key 출력&복사하기)

ssh-keygen -t rsa; 
chmod 700 ~/.ssh; 
chmod 600 ~/.ssh/id_rsa; 
chmod 644 ~/.ssh/id_rsa.pub; 
touch ~/.ssh/authorized_keys; 
chmod 600 ~/.ssh/authorized_keys;
cat ~/.ssh/id_rsa.pub;


2. GitLab 브라우저에서 계정 Profile에 SSH-KEY등록
- 복사한 rsa_key를 GitLab 계정에 등록

- login > 계정정보(우측상단tab) > settings(Click)
- (좌측tab) SSH Keys > Key 항목 > rsa_key(paste) > Add key(Button Click) 
- 하단, Your SSH keys 항목 등록여부 확인 


3. 정상여부 확인(Client 사용될 Labtop/Server)

ssh -T git@gitlab.com

- 최초 호출 시, known_hosts 등록여부를 물어본다. (당연히 yes)
- 결과 :  welcome to GitLab, @${GitLab에서 사용중인 계정명}!

4. 프로젝트 연동할 URL 주소 복사

- 프로젝트 이동 > Clone(Button Click) > Clone With SSH > Copy URL to clipboard(Button Click)


5. git clone 하여 연동확인
- git clone 복사한 url paste

git clone git@gitlab.com:${프로젝트그룹}/${프로젝트명}.git

 


#- References
https://docs.gitlab.com/ce/ssh/README.html