반응형

Google Cloud Platform(GCP)에서는 Compute Engine을 통해 가상 머신(VM)을 쉽게 생성하고 관리할 수 있습니다.
이 글에서는 GCP에서 생성한 VM 인스턴스에 SSH로 접속하는 방법을 단계별로 설명합니다.

 

✅ 1. 사전 준비

SSH 접속을 위해 다음 사항이 준비되어 있어야 합니다:

  • ✅ GCP 계정 및 프로젝트 생성 완료
  • ✅ VM 인스턴스 생성 완료
  • ✅ 로컬 환경에 Google Cloud SDK (gcloud) 설치 및 로그인

설치 후 로그인:

gcloud auth login

 

활성화할 프로젝트 지정:

gcloud config set project [PROJECT_ID]

 

✅ 2. gcloud compute ssh 명령어로 SSH 접속하기

GCP에서는 gcloud 명령어로 SSH 키 생성 → VM 등록 → 접속 과정을 자동으로 처리할 수 있습니다.

gcloud compute ssh [VM_INSTANCE_NAME] --zone=[ZONE]

 

실행 시:

  • 로컬에 SSH 키가 없으면 자동 생성
  • VM 인스턴스에 공개키 자동 등록
  • SSH 터널을 통해 접속

✅ 3. 수동 SSH 접속 (이미 키가 등록된 경우)

공개키가 이미 VM에 등록되어 있다면, 일반적인 SSH 명령어로 접속할 수 있습니다:

ssh -i ~/.ssh/google_compute_engine [USERNAME]@[EXTERNAL_IP]

※ 기본 SSH 키는 ~/.ssh/google_compute_engine에 생성됩니다.
※ 퍼미션 오류를 방지하려면 .ssh 폴더는 700, 개인키는 600으로 설정하세요.

 

✅ 4. 접속 오류 발생 시 점검사항

에러 메시지 원인 및 해결
Permission denied (publickey) SSH 키가 VM에 등록되지 않았거나 권한 문제
connection timed out 방화벽 설정에서 포트(22) 허용 안 됨
not found: [VM name] zone 또는 project 설정이 잘못되었을 가능성
 

🔧 확인 명령어들

  • 프로젝트 확인:
gcloud config list project
  • 인증된 사용자 확인:
gcloud auth list
  • VM 목록 확인:
gcloud compute instances list

 

#GCP #GoogleCloud #ComputeEngine #SSH접속 #클라우드서버 #VM인스턴스 #gcloud #서버관리 #리눅스서버 #개발환경세팅 #인프라구축 #DevOps #클라우드기초 #우분투서버 #Debian서버 #IT블로그 #개발자팁 #백엔드개발 #터미널사용법

728x90
반응형
반응형

1. CA 생성 시 입력하는 패스워드

역할 및 목적
CA(Certificate Authority)를 생성할 때 입력하는 패스워드는 CA의 개인 키를 암호화하는 데 사용됩니다. 예를 들어, elasticsearch-certutil ca 명령어를 통해 CA 인증서를 만들 때, 이 패스워드는 CA의 개인 키(예: http_ca.key)를 안전하게 암호화하여 저장합니다. 이후, CA를 이용해 다른 인증서를 서명할 때도 이 암호가 필요할 수 있습니다.

사용 시점과 영향

  • 사용 시점: 주로 CA 관련 작업, 예를 들어 새로운 인증서를 서명하거나 CA 인증서를 재발급할 때 필요합니다.
  • 실행 후 영향: 이 패스워드는 CA의 개인 키를 보호하는 역할을 하며, 운영 중에는 CA 관련 작업이 발생하지 않는 한 별도의 런타임 영향은 없습니다.

2. Elasticsearch keystore의 xpack.security.http.ssl.keystore.secure_password

역할 및 목적
이 설정은 Elasticsearch가 HTTPS 통신에 사용하는 HTTP keystore(예: http.p12) 파일을 열 때 사용됩니다. keystore 파일에는 HTTP 인증서와 그에 대응하는 개인 키가 포함되어 있으며, 이를 통해 Elasticsearch는 안전한 HTTPS 연결을 설정합니다.

사용 시점과 영향

  • 사용 시점: Elasticsearch가 시작할 때 keystore 파일을 열어 HTTPS 연결을 위한 인증서와 개인 키를 읽어들일 때 이 패스워드가 사용됩니다.
  • 실행 후 영향: 만약 이 패스워드가 올바르지 않다면, Elasticsearch는 keystore를 열 수 없게 되어 HTTPS 연결을 설정하지 못합니다. 그 결과 클라이언트(예: Kibana)와의 보안 통신에 문제가 발생할 수 있습니다.

3. 두 패스워드는 서로 달라도 괜찮은가?

두 패스워드는 각각 완전히 다른 역할을 수행합니다.

  • CA 패스워드: CA의 개인 키를 암호화하여 보호하며, CA 관련 서명 작업에 사용됩니다.
  • Keystore 패스워드: Elasticsearch가 HTTPS 통신에 필요한 인증서와 개인 키가 저장된 keystore 파일을 열 때 사용됩니다.

따라서 보안 정책에 따라 두 패스워드는 반드시 동일할 필요는 없으며, 서로 독립적으로 관리하는 것이 일반적입니다.


결론

보안 설정을 보다 명확하게 구성하기 위해서는 각 패스워드의 역할과 사용 시점을 정확히 이해하는 것이 중요합니다.

  • CA 생성 시 입력하는 패스워드: CA의 개인 키 암호화 및 서명 작업에 사용.
  • xpack.security.http.ssl.keystore.secure_password: Elasticsearch가 HTTPS 통신을 위해 keystore 파일을 열 때 사용.
728x90
반응형
반응형

 

방법은 CA부터 만들고 elasticsearch-certutil http에서 생성한  CA를 선택해서 진행하는 방식과

elasticsearch-certutil http로 바로 시작해서 CA를 만들면서 시작하는 방식이 있는데 공식문서에는 첫번재 방식에 대해서 자세히 설명이 되어 있지만 저는 두번째 방식으로 진행했습니다.

 

우분투 18.04에 elasticsearch와 kibana만 설치하고 진행했습니다.

#우분투에 설치된 경로 기준
sudo /usr/share/elasticesearch/bin/elasticsearch-certutil htt

해당 명령어를 입력하면 인증서를 만들기 위해 옵션 설정 항목들이 나옵니다.

## Elasticsearch HTTP Certificate Utility

# Do you wish to generate a Certificate Signing Request (CSR)?
Generate a CSR? [y/N]n

## Do you have an existing Certificate Authority (CA) key-pair that you wish to use to sign your certificate?
Use an existing CA? [y/N]n

## CA Generation Options
Do you wish to change any of these options? [y/N]n

## CA password
CA password:  [<ENTER> for none] 패스워드입력
Repeat password to confirm: 패스워드입력

## How long should your certificates be valid?
For how long should your certificate be valid? [5y] 2y

## Do you wish to generate one certificate per node?
Generate a certificate per node? [y/N]n

## Which hostnames will be used to connect to your nodes?
localhost

Is this correct [Y/n]y

## Which IP addresses will be used to connect to your nodes?
127.0.0.1

Is this correct [Y/n]y

## Other certificate options
Do you wish to change any of these options? [y/N]n

## What password do you want for your private key(s)?
Provide a password for the "http.p12" file:  [<ENTER> for none] 패스워드입력
Repeat password to confirm: 패스워드입력

## Where should we save the generated files?
What filename should be used for the output zip file? [/usr/share/elasticsearch/elasticsearch-ssl-http.zip] 엔터

마지막 output zip file 에서 파일명 변경없이 엔터 치면 Zip file written to /usr/share/elasticsearch/elasticsearch-ssl-http.zip 메시지와 함께 제안해준 파일이 생성이 됩니다.

sudo unzip /usr/share/elasticsearch/elasticsearch-ssl-http.zip -d /etc/elasticsearch/certs/http

압축파일을 /etc/elasticsearch/certs/http 아래에 풀었는데요 기본적으로 /etc/elasticsearch/certs까지 구성되어 있기 때문에 http 디렉토리를 먼저 만들고 진행하면 됩니다.

Archive:  /usr/share/elasticsearch/elasticsearch-ssl-http.zip
   creating: /etc/elasticsearch/certs/http/elasticsearch/
  inflating: /etc/elasticsearch/certs/http/elasticsearch/README.txt  
  inflating: /etc/elasticsearch/certs/http/elasticsearch/http.p12  
  inflating: /etc/elasticsearch/certs/http/elasticsearch/sample-elasticsearch.yml  
   creating: /etc/elasticsearch/certs/http/ca/
  inflating: /etc/elasticsearch/certs/http/ca/README.txt  
  inflating: /etc/elasticsearch/certs/http/ca/ca.p12  
   creating: /etc/elasticsearch/certs/http/kibana/
  inflating: /etc/elasticsearch/certs/http/kibana/README.txt  
  inflating: /etc/elasticsearch/certs/http/kibana/elasticsearch-ca.pem  
  inflating: /etc/elasticsearch/certs/http/kibana/sample-kibana.yml

압축을 풀면 위와 같이 어떤 파일들이 압축해제 되었는지 보여줍니다. 

파일들에 대해서 요약해보자면 

  • Elasticsearch 관련 파일 (/elasticsearch/ 디렉터리)
    • http.p12: Elasticsearch HTTP 통신에 사용할 인증서와 개인 키.
    • sample-elasticsearch.yml: 해당 인증서를 사용하는 설정 예시.
  • CA 관련 파일 (/ca/ 디렉터리)
    • ca.p12: Elasticsearch HTTP 인증서를 서명한 CA 정보가 담긴 키스토어.
  • Kibana 관련 파일 (/kibana/ 디렉터리)
    • elasticsearch-ca.pem: Kibana가 Elasticsearch의 인증서를 검증할 때 사용하는 CA 인증서.
    • sample-kibana.yml: Kibana의 SSL/TLS 설정 예시 파일.
sudo vi /etc/elasticsearch/elasticsearch.yml

elasticsearch.yml  파일을 열어서 keystore.path 설정 변경을 해줍니다.

xpack.security.http.ssl:
	enabled: true
    keystore.path: certs/http/elasticsearch/http.p12

그리고 Elasticsearch의 보안 설정에 개인 키의 비밀번호를 추가합니다.

sudo /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password

기존에 생성되어 있는 키가 있기때문에 덮어씌우기하시면 됩니다.

sudo systemctl restart elasticsearch

elasticsearch를 재시작해하면 elasticsearch와 관련된 설정은 끝이고 kibana 설정을 해보겠습니다.

sudo cp /etc/elasticsearch/certs/http/kibana/elasticsearch-ca.pem /var/lib/kibana/

압축파일에 있던 인증서를 복사합니다.

sudo openssl x509 -in /var/lib/kibana/elasticsearch-ca.pem -noout -fingerprint -sha256

설정파일을 수정할때 ca_trusted_fingerprint값도 바꿔야 하기때문에 미리 출력합니다.

sudo vi /etc/kibana/kibana.yml

kibana.yml파일을 열어서 기존에 있던 인증서 설정값을 새로운 인증서로 변경합니다.

elasticsearch.ssl.certificateAuthorities: [/var/lib/kibana/elasticsearch-ca.pem]
xpack.fleet.outputs:[{......, ca_trusted_figerprint: "sha256 값"
sudo systemctl restart kibana

kibana를 재실행 하면 설정은 끝납니다.

 

 

728x90
반응형

+ Recent posts