OpenSSL은 SSL/TLS 인증서를 위한 만능 도구입니다. 이 사이트의 다른 모든 글에서 OpenSSL 명령어를 참조합니다 — 이 페이지는 그것들을 한 곳에 모아 놓은 것입니다.
인증서 확인
인증서 세부 정보 보기 (원격 서버)
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -text
만료일 확인
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -enddate
주체와 SAN 확인
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName
발급자(어떤 CA) 확인
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -issuer
로컬 인증서 파일 확인
openssl x509 -in cert.pem -noout -text
openssl x509 -in cert.pem -noout -dates # 날짜만
openssl x509 -in cert.pem -noout -subject # 주체만
openssl x509 -in cert.pem -noout -ext subjectAltName # SAN만
인증서 체인 검증
체인 완전성 확인 (원격)
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null
# 확인 사항:
# Verify return code: 0 (ok) ← 체인이 완전함
# Verify return code: 21 (unable to verify) ← 체인이 불완전함
체인 파일에 대한 인증서 검증
openssl verify -CAfile chain.pem cert.pem
# 예상: cert.pem: OK
인증서와 키의 일치 여부 확인
# 이 두 해시가 동일해야 함
openssl x509 -noout -modulus -in cert.pem | openssl md5
openssl rsa -noout -modulus -in privkey.pem | openssl md5
# ECDSA 키의 경우:
openssl ec -in privkey.pem -pubout 2>/dev/null | openssl md5
openssl x509 -in cert.pem -pubkey -noout | openssl md5
키 생성
ECDSA P-256 (권장)
openssl ecparam -genkey -name prime256v1 -noout -out privkey.pem
RSA 2048
openssl genrsa -out privkey.pem 2048
RSA 4096
openssl genrsa -out privkey.pem 4096
CSR 생성
ECDSA
openssl req -new -key privkey.pem -out csr.pem -subj "/CN=example.com"
SAN 포함 (멀티 도메인)
openssl req -new -key privkey.pem -out csr.pem \
-subj "/CN=example.com" \
-addext "subjectAltName=DNS:example.com,DNS:www.example.com"
CSR 검사
openssl req -in csr.pem -noout -text
형식 변환
PEM → PFX (Windows/IIS용)
openssl pkcs12 -export -out cert.pfx -inkey privkey.pem -in cert.pem -certfile chain.pem
PFX → PEM
openssl pkcs12 -in cert.pfx -clcerts -nokeys -out cert.pem
openssl pkcs12 -in cert.pfx -nocerts -nodes -out privkey.pem
openssl pkcs12 -in cert.pfx -cacerts -nokeys -out chain.pem
PEM → DER
openssl x509 -in cert.pem -outform DER -out cert.der
DER → PEM
openssl x509 -in cert.der -inform DER -outform PEM -out cert.pem
TLS 연결 디버그
협상된 TLS 버전 확인
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | grep "Protocol"
특정 TLS 버전 테스트
# TLS 1.2 테스트
echo | openssl s_client -connect example.com:443 -servername example.com -tls1_2 2>/dev/null | grep "Protocol"
# TLS 1.3 테스트
echo | openssl s_client -connect example.com:443 -servername example.com -tls1_3 2>/dev/null | grep "Protocol"
전체 핸드셰이크 표시
openssl s_client -connect example.com:443 -servername example.com -msg
지원되는 암호화 스위트 확인
# 서버가 수락하는 모든 암호화 스위트 나열
nmap --script ssl-enum-ciphers -p 443 example.com
자체 서명 인증서 생성 (개발 전용)
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 \
-keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
신뢰할 수 있는 localhost HTTPS는 mkcert를 대신 사용하세요.
별도 파일로 fullchain.pem 생성
cat cert.pem chain.pem > fullchain.pem
순서가 중요합니다: 인증서가 먼저, 그다음 중간 인증서.
자주 묻는 질문
OpenSSL을 어떻게 설치하나요?
대부분의 Linux 배포판에 포함되어 있습니다. macOS: brew install openssl. Windows: Git for Windows(OpenSSL 포함)를 통해 설치하거나 Chocolatey(choco install openssl)를 사용하세요.
openssl x509와 openssl s_client의 차이점은?
x509는 로컬 인증서 파일을 읽습니다. s_client는 원격 서버에 연결하여 인증서를 가져옵니다. 라이브 서버를 확인하려면 s_client를, 디스크의 파일을 검사하려면 x509를 사용합니다.
명령에서 “unable to load certificate”가 표시되는 이유는?
파일이 PEM(텍스트)이 아닌 DER 인코딩(바이너리)일 수 있습니다. 명령에 -inform DER을 추가합니다:
openssl x509 -in cert.der -inform DER -noout -text