[Linux] SSL (자가 서명)사설 인증서 생성하기

 

 

이버 포스팅은 SSL 사설 인증서 생성에 대한 내용입니다.

 

실제 서비스에서 인증서를 적용하기 위해서는 공인 인증기관을 통해서 발급이 필요합니다.

테스트 및 학습 목적이시라면 openssl를 통해 사설 인증서를 발급받으시면 됩니다.

 

 

 

1단계. 개인키 생성

 

인증 기관 개인키를 만드는 단계인데요

사설 인증서(자가 서명 인증서)는  인증 기관이 없기 때문에 스스로 서명하여 인증서를 만듭니다.

[root@k8s-worker-1 make_ssl]# openssl genrsa -des3 -out ssl_1.key 2048
Generating RSA private key, 2048 bit long modulus
....+++
..........................................................+++
e is 65537 (0x10001)
Enter pass phrase for ssl_1.key:
Verifying - Enter pass phrase for ssl_1.key:

openssl genrsa -des3 -out ssl_1.key 2048

 

 

2단계. CSR(Certificate Sinning Request) 생성

 

인증서 발급에 필요한 내용을 담고 있는 요청서입니다.

1단계에서 생성한 key를 가지고 요청서를 생성합니다.

[root@k8s-worker-1 make_ssl]# openssl req -new -key ssl_1.key -out ssl_1.csr
Enter pass phrase for ssl_1.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:KR
State or Province Name (full name) []:Seoul
Locality Name (eg, city) [Default City]:GangNam
Organization Name (eg, company) [Default Company Ltd]:sh-safer
Organizational Unit Name (eg, section) []:sh-safer
Common Name (eg, your name or your server's hostname) []:sh-safer.com
Email Address []:admin@sh-safer.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

 

 

3단계. 개인키에서 패스워드 제거

 

현재 생성된 개인키로 apache나 nginx에 적용을 하면 데몬을 구동할 때마다 key 패스워드를 입력해 주어야 합니다.

매번 패스워드 입력하는 게 번거로워 패스워드를 제거합니다. 

[root@k8s-worker-1 make_ssl]# openssl rsa -in ssl_1.key -out ssl_1_nopass.key
Enter pass phrase for ssl_1.key:
writing RSA key

 

 

 

 

4단계. (자가 서명) 사설 인증서 생성

 

생성한 key 및 csr 파일로 인증서를 생성합니다.

[root@k8s-worker-1 make_ssl]# openssl x509 -req -days 365 -in ssl_1.csr -signkey ssl_1_nopass.key  -out ssl_1.crt
Signature ok
subject=/C=KR/ST=Seoul/L=GangNam/O=sh-safer/OU=sh-safer/CN=sh-safer.com/emailAddress=admin@sh-safer.com
Getting Private key

 

파일 구성 확인

[root@k8s-worker-1 make_ssl]# ll
합계 16
-rw-r--r--. 1 root root 1314 10월  9 19:37 ssl_1.crt
-rw-r--r--. 1 root root 1058 10월  9 19:33 ssl_1.csr
-rw-r--r--. 1 root root 1751 10월  9 19:19 ssl_1.key
-rw-r--r--. 1 root root 1679 10월  9 19:35 ssl_1_nopass.key

 

 

추가. 인증서 내용 확인

 

key 내용 확인

openssl rsa -text -in [key 파일명]

 

CSR 요청서 내용 확인

openssl req -in [scr 파일명] -noout -text

 

인증서 내용 확인

openssl x509 -in [crt 파일명]  -noout -text

댓글

Designed by JB FACTORY

loading