리눅스 SSL 사설 인증서 생성하기
2014. 5. 22. 16:06 |
리눅스
웹서버에 SSL 인증서를 설치하려면... 물론 돈을 내고 Symantec, Comodo 등 유명 CA(Certification Authority)에서 인증서를 구매하면 된다. 하지만 테스트나 내부 용도로 HTTPS를 올리려면, 굳이 인증서를 구매할 필요는 없겠다.
아래는 openssl로 RSA Private Key 생성, CSR(Certificate Signing Request) 생성, 사설 인증서를 발급하는 과정이다.
[root@centos cert]#
[root@centos cert]# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
...............................+++
..........+++
e is 65537 (0x10001)
[root@centos cert]#
[root@centos cert]# openssl req -new -key server.key -out server.csr
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]:Seoul
Organization Name (eg, company) [Default Company Ltd]:snoopybox
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:snoopybox.co.kr
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@centos cert]#
[root@centos cert]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=KR/ST=Seoul/L=Seoul/O=snoopybox/CN=snoopybox.co.kr
Getting Private key
[root@centos cert]#
[root@centos cert]# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
...............................+++
..........+++
e is 65537 (0x10001)
[root@centos cert]#
[root@centos cert]# openssl req -new -key server.key -out server.csr
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]:Seoul
Organization Name (eg, company) [Default Company Ltd]:snoopybox
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:snoopybox.co.kr
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@centos cert]#
[root@centos cert]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=KR/ST=Seoul/L=Seoul/O=snoopybox/CN=snoopybox.co.kr
Getting Private key
[root@centos cert]#
openssl genrsa -out server.key 2048
=> RSA 2048 비트의 Private Key를 생성한다.
openssl req -new -key server.key -out server.csr
=> CSR을 생성한다. X.509에 필요한 몇가지 정보들을 입력한다.
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
=> 유효기간 365일짜리 사설인증서를 생성한다.
위 3가지 작업을 완료하면 3개의 파일이 생성되는데
server.crt server.csr server.key
인증서를 생성했다면 CSR 파일은 삭제해도 된다.
아래 예제처럼 아파치 설정파일에 Private Key와 인증서를 설정해주면 된다.
SSLCertificateFile "/app/apache/conf/cert/server.crt"
SSLCertificateKeyFile "/app/apache/conf/cert/server.key"
아래는 위 키와 인증서를 설치해서 테스트해본 모습.
추가1 - 2014.07.28
Private Key 생성시 des3로 암호화 하는 경우가 많다. 이 경우 아파치 재기동시 패스워드를 입력해야 하는데, SSLPassPhraseDialog에 쉘 스크립트를 지정해서 처리해도 되지만, Private Key의 암호화를 풀어서 사용해도 된다. 아래와 같이 암호화를 풀어보자.
openssl rsa -in server.key -out nopass.key
Private Key 파일이 암호화 되어 있는지 확인해보려면 그냥 파일을 까보면 된다. 암호화 되어 있는 경우 아래와 유사한 내용이 상단에 적혀 있다.
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,7AADA7F286437B35
'리눅스' 카테고리의 다른 글
리눅스 bash IP 유효성 검사 (12) | 2014.06.19 |
---|---|
CentOS yum repository mirror 구축하기 (2) | 2014.06.19 |
리눅스 하이퍼쓰레딩(Hyper Threading) 활성화 확인 방법 (3) | 2014.06.15 |
리눅스 SSL 인증서 만료일 확인 (3) | 2014.05.28 |
리눅스 SSL 사설 인증서 생성하기 (1) | 2014.05.22 |
리눅스 SSH RSA 비대칭키로 패스워드 없이 접속 (4) | 2014.05.20 |
리눅스 본딩 구성 (4) | 2014.02.18 |
리눅스 IP를 변수로 (0) | 2014.02.04 |
우분투 서비스 컨트롤 방법 (7) | 2014.01.01 |
2014.05.23 09:50
잘보고 갑니다. ^^