본문 바로가기

프로그래밍

OpenSSL / OpenSSH 간단 사용법

SSH : 원격 컴퓨터에 안전하게 액세스하기 위한 유닉스 기반의 명령 인터페이스 및 프로토콜


인증 방법 :


http://www.eldos.com/security/articles/1962.php

  • Public key authentication (main authentication method)
  • Password authentication
  • Host-based authentication
  • Keyboard authentication 

2. 명령어

1) openssl 버전 확인
openssl version

2) 키 생성
openssl genrsa -des3 -out 키이름.key 1024 : 3DES로 암호화. 비밀번호 설정 필요.

3) 암호화 하지 않고 키 생성
openssl genrsa -out 키이름.key 1024


3-1) 비밀키로 공개키 생성
openssl rsa -in 비밀키명.key -pubout -out 공개키명.key

 
4) 기존 비밀키에 패스워드 추가
openssl rsa -in out 키이름.key -des3 -out 새키이름.key

5) 기존 비밀키에 패스워드 제거
openssl rsa -in 키이름.key -out 새로운키이름.key
6) 키 내용 확인
openssl 키종류 -noout -text -in 키이름.key
ex) openssl rsa -noout -text -in 키이름.key

7) 자체 서명 인증서 생성
openssl req -new -key 키이름.key -x509 -out 인증서이름.crt
openssl req -new -x509 -nodes -sha1 -days 365 -key server.key -out server.crt


Enter pass phrase for test.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) [AU]: 국가 코드(2자리)
State or Province Name (full name) [Some-State]: 주 / 도
Locality Name (eg, city) []: 시
Organization Name (eg, company) [Internet Widgits Pty Ltd]: 회사명 등
Organizational Unit Name (eg, section) []: 부서 등
Common Name (e.g. server FQDN or YOUR name) []: 이름이나 서버 주소
Email Address []: 이메일 주소



8) 인증서 확인
openssl x509 -noout -text -in 인증서파일.crt
openssl x509 -in ca.der -inform DER -text (DER 포맷인 경우)

9) DSA key 생성

(1) parameters 생성
openssl dsaparam -out 파라미터.pem 2048

(2) key 생성
openssl gendsa -des3 -out 키이름.key 파라미터.pem

10) CSR생성 (인증서 서명 요청을 위해 필요)
openssl req -new -key 키이름.key -out csr이름.csr

10-1) CSR 확인
openssl req -noout -text -in csr이름.csr



11) pkcs12 변환
openssl pkcs12 -export -in 파일명 -inkey 키이름.key -out pfx명.pfx


12) 인증서 인코딩 포멧 변경
- openssl 이 생성하는 인증서의 인코딩은 발급 시 옵션을 주지 않으면 디폴트가 PEM (base64 encoding)이다.
- Java 등에서 사용하기 위한 DER 포맷(바이너리)으로 변경은 다음과 같이 수행한다.
openssl x509 -in ca.crt -out ca.der -outform DER