STUDY/GIT

GIT/ GCP 연동

sh.ds 2023. 10. 17. 18:19
이번엔 GITHUB과 GCP를 연동하는 시간을 가져보자

GIT 설치

당연하겠지만 깃헙과 연결하기 위해서는 GIT이 필요하다. 터미널에서 GIT을 설치해보자

 

(base) ***@***:~$ sudo apt-get update -y
(base) ***@***:~$ sudo apt-get upgrade -y
(base) ***@***:~$ sudo apt install git

#확인차 버전체크
(base) ***@***:~$ git --version

 

이후 Github에 연동이 잘 되는지 확인할 repository를 하나 만든다.

 

✅ 보안을 위해 Private으로 만들었다

 


SSH Key 값 설정하기

다음으로 할 것은 ssh의 Key 값을 설정해주는 것이다.

아래의 코드를 실행하고 엔터를 계속 눌러준다면 그 밑의 사진과 같은 결과가 나온다.

(base) ***@***:~$ ssh-keygen -t rsa -b 4096 -C “깃허브 이메일 주소”

결과가 잘 나온다면 키값을 조회하는 명령어를 실행한다. 

(base) ***@***:~$ cat .ssh/id_rsa.pub

코드 결과를 전부 복사한다.


생성된 Key값을 github에 등록할 시간이다.

Github ➡ MyProfile ➡ Settings 로 이동한다.

 

 

Settings의 SSH and GPG keys 메뉴로 들어가 New SSH Key를 클릭한다.

 

 

SSH Key를 구분할 수 있는 이름을 지어주고 아까 복사한 Key값을 붙여넣기 해주면 된다.

 


 

메타 데이터 등록하기

git에서의 등록을 끝냈으니 이제는 google cloud에서 등록해야 한다.

 

GCP 사이드바의 Compute engine으로 이동해 설정의 메타데이터를 클릭한다.

 

 

페이지의 SSH 키를 클릭하고 항목추가 ➡ 아까 복사한 Key값을 붙여넣기 한다.

 

사전에 추가한 ssh키 1 때문에 혼동하는일이 없었으면 한다.

 


 github과의 연동 작업만이 남아있다.

 

  1. Code의 SSH 탭에서 주소를 복사
  2. SSH의 경로를 조정
  3. git clone
(base) ***@***:~$ pwd
/home/user_id
(base) ***@***:~$ git clone git@github.com:Sang-Hyeok-Lee/GCP_to_Git.git
Cloning into 'GCP_to_Git'...
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.200.245.247'' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.

(base) ~$ ls
Untitled.ipynb  miniconda3  mulcampFP

 

다음과 같이 ls 결과가 나온다면 성공이다.


Github 로그인 및 테스트

제대로 연동이 되기 위해 테스트는 필수다.

 

vi 편집기로 README.md 파일에 GCP & GIT Connected 를 작성해준다.

 

그리고 github repo로 경로를 옮기고 로그인을 진행한다.

 

           ✅user_email과 user_name을 바꿔주는 걸 빼먹지 말자

(base) ***@***:~/github_repo$ git config --global user.email "user_email"
(base) ***@***:~/github_repo$ git config --global user.name "user_name"

 

 

이제 git add commit push를 진행한다.

 

(base) ***@***:~/GCP_to_Git$ git add .
(base) ***@***:~/GCP_to_Git$ git commit -m "updated"
[main 4e2d232] updated
 1 file changed, 5 insertions(+), 1 deletion(-)
(base) ***@***:~/GCP_to_Git$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 309 bytes | 309.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:Sang-Hyeok-Lee/GCP_to_Git.git
   5533b86..4e2d232  main -> main

 

Github의 README 파일이 제대로 바뀌어 있다면 성공이다.