GCP 콘솔에 접속한다.

외부에서 ssh로 접속하고자하는 VM 인스턴스를 콘솔에서 SSH를 클릭하여 접속한다.

 

key 생성

오픈된 화면에서 ssh-keygen -t rsa -C username 명령어로 keypair를 생성한다. 계정의 홈 디렉토리 하위의 .ssh 디렉토리에 id_rsa private key와 id_rsa.pub 라는 public key가 생성된다.

$ ssh-keygen -t rsa -C username

 

아래 명령어로 ssh 인증키를 등록한다. 


cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys

또는 구글 콘솔에서 "Compute Engine" 메뉴의 "메타데이터"를 클릭한 후 SSH public key를 등록해준다.

등록할 key는 VM 인스턴스에 생성되어 있는 id_rsa.pub 내용을 등록한다.

 

이제 VM 인스턴스에 생성되어 있는 private key를 다운로드한다. 

GCP 콘솔에서 오픈한 SSH 창의 우측 상단에 "Download file"을 클릭한 후 다운로드 화면이 나오면 private key가 생성되어 있는 경로명과 파일명을 입력한다. 예시) /home/username/.ssh/id_rsa

다운로드한 private key를 

윈도우인 경우 C:\Users\<username>\.ssh 하위에 복사한다.

리눅스인 경우에는 /home/<username>/.ssh 하위에 복사한다.

 

아래의 명령어로 대상 서버에 접속한다.

ssh <username>@35.216.96.152

또는 ssh -i c:\users\<username>\.ssh\id_rsa username@35.216.96.152 를 수행한다.

여기서 -i 옵션은 private key의 위치를 지정한다.

IP Address는 GCP VM 인스턴스의 외부 IP 이다.

> ssh username@351.216.96.152

Linux vm-aicallbot-admin-prd-01 4.19.0-18-cloud-amd64 #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Mar 11 07:38:49 2022 from 35.235.242.81
username@vm-admin-prd-01:~$

 

'GCP' 카테고리의 다른 글

GCP-interconnect  (0) 2022.03.22
GCP - vpc peering 설정  (0) 2022.03.18
GCP - gcloud 설치 on linux  (0) 2022.03.13
GCP VM ID/Password 접속  (0) 2022.03.11
GCP disk 추가  (0) 2022.02.18

+ Recent posts