/엔지니어/보안 설정/openssl 실전 — 인증서 생성, 확인, 변환
보안 설정중급UbuntuDebianCentOSmacOSopenssl인증서TLS

openssl 실전 — 인증서 생성, 확인, 변환

자체 서명 인증서 생성, CSR 발급, 인증서 정보 확인, PEM/PFX 형식 변환까지 openssl 핵심 명령어를 정리합니다.

인증서 정보 확인

Bash
# 원격 서버 인증서 확인
openssl s_client -connect example.com:443 -showcerts </dev/null

# 만료일만 빠르게 확인
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates

# 로컬 인증서 파일 확인
openssl x509 -in cert.pem -noout -text

# 주요 정보만
openssl x509 -in cert.pem -noout -subject -issuer -dates

# 인증서 지문 (fingerprint)
openssl x509 -in cert.pem -noout -fingerprint -sha256

자체 서명 인증서 생성 (개발/테스트용)

Bash
# 개인키 + 인증서 한 번에 생성 (365일)
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
  -subj "/C=KR/ST=Seoul/L=Seoul/O=MyOrg/CN=localhost"

# SAN 포함 (크롬 호환)
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
  -subj "/CN=localhost" \
  -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"

CSR(Certificate Signing Request) 생성

Bash
# 개인키 생성
openssl genrsa -out server.key 4096

# CSR 생성
openssl req -new -key server.key -out server.csr \
  -subj "/C=KR/ST=Seoul/O=MyCompany/CN=example.com"

# CSR 내용 확인
openssl req -in server.csr -noout -text

형식 변환

Bash
# PEM → DER (바이너리)
openssl x509 -in cert.pem -outform der -out cert.der

# DER → PEM
openssl x509 -in cert.der -inform der -out cert.pem

# PEM → PFX/P12 (Windows/IIS용)
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem \
  -certfile chain.pem -passout pass:mypassword

# PFX → PEM
openssl pkcs12 -in cert.pfx -out cert.pem -nodes -passin pass:mypassword

# 개인키 암호 제거
openssl rsa -in encrypted.key -out decrypted.key

만료 일괄 모니터링 스크립트

Bash
#!/bin/bash
DOMAINS=("example.com" "api.example.com")
WARN_DAYS=30

for domain in "${DOMAINS[@]}"; do
  expiry=$(echo | openssl s_client -connect "$domain:443" 2>/dev/null \
    | openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)

  if [ -z "$expiry" ]; then
    echo "FAIL: $domain (연결 불가)"
    continue
  fi

  days=$(( ($(date -d "$expiry" +%s) - $(date +%s)) / 86400 ))

  if [ "$days" -lt "$WARN_DAYS" ]; then
    echo "WARNING: $domain — ${days}일 후 만료"
  else
    echo "OK: $domain — ${days}일 남음"
  fi
done
#openssl#인증서#TLS#SSL#보안
편집 안내 · Editorial Note

이 가이드는 AI 도구를 활용해 초안을 구성하고 사람이 명령어·문맥을 검토해 발행했습니다. 운영체제와 도구 버전에 따라 결과가 달라질 수 있으므로 적용 전 공식 문서를 함께 확인하세요. 오류를 발견하시면 이메일로 제보해 주세요.

질문 & 답변 (Q&A)

이 가이드에 대해 궁금한 점을 질문해보세요. 확인 후 답변드립니다.