기존에 bitbucket 저장소를 https 방식으로 연결하여 사용 중이었는데, 서버에서 git pull 받을 때마다 해시태그 형식의 개인 앱 비밀번호를 입력해야해서 너무 번거로웠다.
그래서 이 참에 ssh 방식으로 전환을 해보려고 한다.
remote url 변경
서버의 ssh public key 복사
bitbucket 에 ssh public key 등록
ssh git 연결 테스트
git pull 작업 실행
(선택) ssh config 설정
$ git remote set-url origin git@bitbucket.org:<워크스페이스명(소문자)>/<저장소명>.git
ssh nxtcorp@<서버 IP>
cat ~/.ssh/id_rsa.pub
예시
ssh -t -vvv git@bitbucket.org
OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /home/nxtcorp/.ssh/config
debug1: /home/nxtcorp/.ssh/config line 1: Applying options for bitbucket.org
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "bitbucket.org" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to bitbucket.org [104.192.141.1] port 22.
debug1: Connection established.
(...)
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 2097152 rmax 32768
debug3: receive packet: type 100
debug2: channel_input_status_confirm: type 100 id 0
PTY allocation request failed on channel 0
모든 과정이 끝났으므로 git pull
작업을 실행해본다.
명령어
git pull origin <브랜치명>
결과
~/.ssh/config
Host bitbucket.org
HostName bitbucket.org
Port 22
HostkeyAlias bitbucket.org
🔥 SSH 보안 방식은 항상 복잡하다.
💡 그래도 한 번 설정해두면 HTTPS 보다 더 간단하게 git source 를 관리할 수 있는 장점이 있다.