Heesung Yang
GPG 공개키/개인키 쌍 만들기
- GPG 버전 2.2.19를 기준으로 작성한 문서다.
- Ubuntu 20.04에 포함된 버전
- CentOS 7은 2.0.22이 설치되어 있고, 명령 실행 결과와 옵션이 약간 다르다.
Key Pair 생성
~$ gpg --full-gen-key
-
생성할 키 종류 선택(RSA)
Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) (14) Existing key from card Your selection? 1
-
키 길이 선택 (4096)
RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (3072) 4096 Requested keysize is 4096 bits
-
키 유효기간 선택 (0)
Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 0 Key does not expire at all
-
사용자 정보 입력
Real name: mykey Email address: example@gmail.com Comment: Testing key You selected this USER-ID: "mykey (Testing key) <example@gmail.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
-
랜덤한 값을 생성하기 위해 여러가지 다양한 입력을 서버에 주어야 한다.
We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
-
이를 손쉽게 하기 위한 툴을 설치하고 또 다른 세션을 열어서 실행(새로운 ssh 세션 혹은 tty)
# Redhat/CentOS ~$ sudo yum install rng-tools # Debian/Ubuntu ~$ sudo apt instal rng-tools # Entropy 생성 ~$ sudo rngd -r /dev/urandom
-
Key 목록 조회
~$ gpg --list-key
/home/hsyang/.gnupg/pubring.kbx
-------------------------------
pub rsa4096 2022-02-27 [SC]
25A589880AD39D49015EE112E65F5A3B08E14BC5
uid [ultimate] mykey (Testing key) <example@gmail.com>
sub rsa4096 2022-02-27 [E]
공개키/비공개키 파일 생성
# public 키 파일 생성
# key 생성 시 입력한 Real name 또는 email 주소를 사용할 수 있음
~$ gpg --armor --export mykey > pub.key
# 또는
~$ gpg --armor --export example@gmail.com > pub.key
# private 키 파일 생성
~$ gpg --armor --export-secret-keys mykey > pri.key
# 또는
~$ gpg --armor --export-secret-keys example@gmail.com > pri.key
Key Pair 삭제
~$ gpg --delete-secret-and-public-keys mykey
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
sec rsa4096/E65F5A3B08E14BC5 2022-02-27 mykey (Testing key) <example@gmail.com>
Delete this key from the keyring? (y/N) y
This is a secret key! - really delete? (y/N) y
pub rsa4096/E65F5A3B08E14BC5 2022-02-27 mykey (Testing key) <example@gmail.com>
Delete this key from the keyring? (y/N) y
Key Pair 가져오기
~$ cat pri.key | gpg --import
Previous post
RPM(YUM) Repository 만들기Next post
DEB(APT) Repository 만들기