[GCP] Google Cloud ssh-key 이용하여 접속

Linux 의 경우 ssh-keygen 명령어를 통하여 아래와 같이 RSA 키페어를 생성 하고,

Windows는 puttygen 을 이용하여 RSA 키페어를 생성 합니다.

Global 모든 Cloud 인스턴스에 접속시 메타데이터 ssh 키 부분에 설정 하시면 되며 단인 Cloud 인스턴스만 접속하기 위해선 Compute Engine -> VM 인스턴스 세부정보 부분의

SSH 키 부분에 등록 하시면 됩니다.

 

Linux 나 MacOS 이용시

RSA 키페어 생성

주의: 키페어 생성시 반드시 Password 를 입력해야 합니다.

엔터를 눌러 스킵시 정상적으로 접속할수 없습니다.

test@docker-test:~$ ssh-keygen -t rsa -C "test@google.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa):
Created directory '/home/test/.ssh'.
Enter passphrase (empty for no passphrase):       // Password 입력
Enter same passphrase again:                      // Password 입력
Your identification has been saved in /home/test/.ssh/id_rsa.
Your public key has been saved in /home/test/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:cJ23OKMOchEWj3oIpyMBKPvdDXlYoeChKovlBuIj1ok test@google.com
The key's randomart image is:
+---[RSA 2048]----+
|o   o . ..       |
|+  o o =.. .     |
|o.o o *+o o .    |
|.o + +++.  o .   |
|*.+.o.o+S + .    |
|=*+.o..... o     |
|+Eoo. o .        |
|o..  o o         |
|        .        |
+----[SHA256]-----+
test@docker-test:~$

키생성시 사용하는 암호를 통하여 ssh 로 접속을 하게 됩니다.

 

id_rsa.pub 퍼블릭키 위치

test@docker-test:~/.ssh$ pwd
/home/test/.ssh
test@docker-test:~/.ssh$ ls
id_rsa  id_rsa.pub
test@docker-test:~/.ssh$

해당 파일(id_rsa.pub) 을 scp 로 Copy 후 Google 클라우드에 등록 합니다.

 

퍼블릭 키 등록

compute engine -> 메타데이터 -> SSH키로 이동 합니다.

+항목추가를 클릭하여 ~/.ssh/id_rsa.pub 내용을 붙여 넣기 합니다.

메타데이터에 key를 추가 하게 되면 해당 키를 통하여 모든 인스턴스에 접속 가능합니다.

저장을 클릭합니다.

 

 ssh 접속

사용하고 있는 Linux 머신에서 접속시 아래와 같은 방법으로 접속하실수 있습니다.

test@docker-test:~/.ssh$ ssh -i id_test google_user@35.xx.xx.200
Warning: Identity file id_test.pub not accessible: No such file or directory.
The authenticity of host '35.xx.xx.200 (35.xx.xx.200)' can't be established.
ECDSA key fingerprint is SHA256:IEUCgjm+1KuzORwPmQH/Vo6SnCztScOWBehFCoSOveo.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '35.xx.xx.200' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/test/.ssh/id_rsa':
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-112-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Tue Feb 27 08:14:28 UTC 2018

  System load:  0.0               Processes:           80
  Usage of /:   12.3% of 9.81GB   Users logged in:     0
  Memory usage: 14%               IP address for eth0: xx.xx.0.2
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

New release '16.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2019.

Last login: Tue Feb 27 08:14:28 2018 from xx.xxx.xx.164
test@ubuntu-trusty-1:~$

 

 

 

Windows 이용시

puttygen 을 이용하여 RSA 키페어를 생성 합니다.

링크에서 iPutty  를 다운 받을수 있습니다.
https://github.com/iPuTTY/iPuTTY/releases

생성버튼 클릭

개인키 저장 버튼을 클릭 합니다.

 

개인키 instance_name.ppk 으로 저장합니다.

아래 부분을 복사 하여 퍼블릭키를 등록 합니다.

 

Google Cloud 에서 Compute Engine -> 메타데이타 -> SSH 키로 이동합니다.

저장을 클릭합니다.

 

ssh-client 를 실행합니다. (putty 이용)

 

Connection -> SSH -> Auth 로 이동후 Browse... 에서 저장한 키파일을 불러 옵니다.

Open 을 클릭 합니다. 

 

접속후 화면

 

단일 인스턴스 접속시 설정 방법

별도의 인스턴스 재시작이 필요하지 않으며 아래와 같은 방법으로 등록만 해주시면 됩니다.

Compute Engine -> VM 인스턴스

ssh key 를 추가할 인스턴스를 클릭합니다.

 

수정을 클릭합니다.

 

페이지 하단에 SSH 키 부분에 추가 하시면 됩니다.

 

페이지 하단의 저장을 클릭합니다.

 

접속시 위와 동일한 방법으로 접속 하시면 됩니다.

 

Last modified: 2019-06-29

Author

Comments

Write a Reply or Comment