한 줄 명령으로 자체 서명된 SSL 인증서를 생성하는 방법

한 줄 명령으로 자체 서명된 SSL 인증서를 생성하는 방법

일반 이름(CN)은 “example.com”을 예로 사용합니다.

openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 \
-keyout example.key -out example.crt \
-subj "/C=US/ST=California/L=Los Angeles/O=Example Company/OU=IT Department/CN=example.com"

위의 명령은 다음을 수행합니다.

  • -new: 새 인증서 서명 요청(CSR)을 생성합니다.

  • -newkey rsa:2048: RSA 알고리즘을 사용하여 2048비트 개인 키를 생성합니다.

  • -days 365: 인증서의 유효 기간을 365일로 설정합니다.

  • -nodes: 개인 키를 암호화하지 마십시오.
  • -x509: 자체 서명된 SSL 인증서를 생성합니다.

  • -keyout example.key: example.key 파일에 프라이빗 키를 저장합니다.

  • -out example.crt: example.crt 파일에 SSL 인증서를 저장합니다.

  • -subj “/C=US/ST=California/L=Los Angeles/O=Example Company/OU=IT Department/CN=example.com”: SSL 인증서의 주체 정보를 지정합니다.

    여기서 일반 이름(CN)은 example.com으로 설정됩니다.

이 명령을 실행하면 example.key 및 example.crt 파일에 각각 개인 키와 SSL 인증서가 생성됩니다.

이제 이를 사용하여 웹 서버 또는 기타 서비스에 안전하게 연결할 수 있습니다.

도메인 codeverse.kr로 자체 서명된 SSL 인증서 생성

$ openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server.key -out server.crt -subj "/C=KR/ST=Seoul/L=Jongno-gu/O=it blog platform/CN=codeverse.kr"
...+.................+.......+........+....+.....+....+......+...........+...+.+...+.....+......+....+..+......+...+....+......+.........+.....+.............+..+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*......+.....+...+.........+......+..........+..+..........+..+....+.....+.+...+...............+..+.+........+.+........+......+.+......+.....+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...........................+.......+.....+.........+.........+...+....+...+..+......+.............+..+..........+.................+.+......+...........+....+......+...+......+.....+.+...+..+............+...+...+.....................+......+.......+.....+.+.....+.......+...+......+.....+.........+.+.........+.....+.........+................+.....+.......+.....+.............+..+...+............+....+.....+.........+......+......+....+......+.........+......+...+...........+....+..............+...............+......+....+..+.+...............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
..........+.....+.......+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+....+...........+.+.....+.........+.........+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
$ ls -l | grep server
-rw-r--r-- 1 root root 1326 Mar 20 20:33 server.crt
-rw------- 1 root root 1704 Mar 20 20:33 server.key
$ openssl x509 -in server.crt -noout -subject -enddate
subject=C = KR, ST = Seoul, L = Jongno-gu, O = it blog platform, CN = codeverse.kr
notAfter=Mar 19 11:33:07 2024 GMT