git pull port 변경하기

BinaryWoo_dev·2023년 7월 11일
0
post-thumbnail

서론


기존에 bitbucket 저장소를 https 방식으로 연결하여 사용 중이었는데, 서버에서 git pull 받을 때마다 해시태그 형식의 개인 앱 비밀번호를 입력해야해서 너무 번거로웠다.
그래서 이 참에 ssh 방식으로 전환을 해보려고 한다.

본론


절차

  1. remote url 변경

  2. 서버의 ssh public key 복사

  3. bitbucket 에 ssh public key 등록

  4. ssh git 연결 테스트

  5. git pull 작업 실행
    (선택) ssh config 설정

    1. remote url 변경

    $ git remote set-url origin git@bitbucket.org:<워크스페이스명(소문자)>/<저장소명>.git

    2. 서버 ssh public key 복사

    서버 접속

    ssh nxtcorp@<서버 IP>

    public key 복사

    cat ~/.ssh/id_rsa.pub
  • 예시

3. bitbucket 에 ssh public key 등록

4. ssh connect 테스트 하기

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

5. git pull 작업 실행

모든 과정이 끝났으므로 git pull 작업을 실행해본다.

명령어

git pull origin <브랜치명> 

결과

(선택) ssh config 설정

  • git remote repository 연결 포트를 따로 설정하거나 host alias 를 설정하고 싶을 때 아래와 같은 형식으로 설정 한다.

~/.ssh/config

Host bitbucket.org
   HostName bitbucket.org
   Port 22
   HostkeyAlias bitbucket.org

결론


🔥 SSH 보안 방식은 항상 복잡하다.
💡 그래도 한 번 설정해두면 HTTPS 보다 더 간단하게 git source 를 관리할 수 있는 장점이 있다.

profile
매일 0.1%씩 성장하는 Junior Web Front-end Developer 💻🔥

0개의 댓글