(http://www.digimoon.net/)
PGP/GPG란?
- 메시지나 파일을 암호화하여 전송할 수 있는 툴. 소스를 배포하는 각종 프로그램의 변조 유무를 검사할 수 있는 프로그램.
- 악의적인 목적으로 소스에 해킹툴이나 바이러스를 내포하여 원본과 다른 소스를 배포할 수 있다.
- 기본적으로 checksum을 이용한 검사 방법이 있으나 변조 가능성 존재.
- 배포자의 서명과 서명된 파일이 제공되므로 소스에 대한 무결성 검사를 할 수 있다.
- 메일이나 중요한 데이터에 대해 서명과 함께 전송함으로써 허가된 사용자만 해당 데이터를 볼 수 있는 권한을 부여할 수 있다.
- 보안 메일, 전자 서명 시스템에서 응용 가능.
자, 그럼 실습을 통해 PGP/GPG의 쓰임새에 대해 알아보도록 합시다.
serv라는 호스트명의 컴과 work라는 호스트명의 컴이 있다고 하겠습니다.
work에서 공개키를 추출하여 이 공개키를 serv로 전송하고 serv는 이 공개키를 자신의 공개키 데이터베이스에 import시켜 사용 가능하게 만듭니다. 그런 다음 serv에서 메일을 하나 작성하여 work로부터 받은 공개키를 이용하여 암호화시켜 work로 전송합니다. 그런 다음 work로 넘어와 암호화된 메일을 자신의 개인키로 복호화시켜 해독하는 것입니다. work에서 추출한 공개키로 암호화시킨 메일은 반드시 work에 저장되어 있는 개인키로만 복호화가 가능하기 때문이죠.
우선 serv와 work에 모두 일반 계정을 하나 생성해 두도록 합니다.
정말 중요한 조건 하나가 있습니다. 메일을 서로 주고 받을 컴의 시간이 서로 동기화되어 있어야 한다는 것입니다. 제가 처음 gpg 배울 때 두 시스템 간의 시간이 일치 않아 결과가 제대로 안 나오는 트러블을 겪었죠. ㅋ
work에 일반 계정으로 접속합니다. 저는 work컴에 work라는 계정을 생성해 놓았습니다. serv컴에는 serv 계정을 생성해 놓았죠.
work에 gpg 실행 파일이 어디에 위치해 있는지 먼저 확인해 보겠습니다.
[work@work ~]$ which gpg
/usr/bin/gpg
[work@work ~]$
/usr/bin/gpg
[work@work ~]$
패키지도 설치되어 있는 지 확인해 볼까요? /usr/bin/gpg 파일이 어떤 패키지의 실행 파일인지 확인해 보려면
[work@work ~]$ rpm -qf /usr/bin/gpg
gnupg-1.4.1-3
[work@work ~]$
gnupg-1.4.1-3
[work@work ~]$
gpg를 사용할 수 있는 준비가 다 되어 있습니다. 이제 gpg의 쓰임새에 대해 알아 보겠습니다.
[work@work ~]$ gpg --help | less
gpg (GnuPG) 1.4.1
Copyright (C) 2005 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details. Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512
Compression: Uncompressed, ZIP, ZLIB, BZIP2 Syntax: gpg [options] [files]
sign, check, encrypt or decrypt
default operation depends on the input data Commands: -s, --sign [file] make a signature
--clearsign [file] make a clear text signature
-b, --detach-sign make a detached signature
-e, --encrypt encrypt data
-c, --symmetric encryption only with symmetric cipher
-d, --decrypt decrypt data (default)
--verify verify a signature
--list-keys list keys
--list-sigs list keys and signatures
--check-sigs list and check key signatures
--fingerprint list keys and fingerprints
-K, --list-secret-keys list secret keys
--gen-key generate a new key pair
--delete-keys remove keys from the public keyring
--delete-secret-keys remove keys from the secret keyring
--sign-key sign a key
--lsign-key sign a key locally
--edit-key sign or edit a key
--gen-revoke generate a revocation certificate
--export export keys
--send-keys export keys to a key server
--recv-keys import keys from a key server
--search-keys search for keys on a key server
--refresh-keys update all keys from a keyserver
--import import/merge keys
--card-status print the card status
--card-edit change data on a card
--change-pin change a card's PIN
--update-trustdb update the trust database
--print-md algo [files] print message digests Options: -a, --armor create ascii armored output
-r, --recipient NAME encrypt for NAME
-u, --local-user use this user-id to sign or decrypt
-z N set compress level N (0 disables)
--textmode use canonical text mode
-o, --output use as output file
-v, --verbose verbose
-n, --dry-run do not make any changes
-i, --interactive prompt before overwriting
--openpgp use strict OpenPGP behavior
--pgp2 generate PGP 2.x compatible messages (See the man page for a complete listing of all commands and options) Examples: -se -r Bob [file] sign and encrypt for user Bob
-a, --armor create ascii armored output
-r, --recipient NAME encrypt for NAME
-u, --local-user use this user-id to sign or decrypt
-z N set compress level N (0 disables)
--textmode use canonical text mode
-o, --output use as output file
-v, --verbose verbose
-n, --dry-run do not make any changes
-i, --interactive prompt before overwriting
--openpgp use strict OpenPGP behavior
--pgp2 generate PGP 2.x compatible messages (See the man page for a complete listing of all commands and options) Examples: -se -r Bob [file] sign and encrypt for user Bob
--clearsign [file] make a clear text signature
--detach-sign [file] make a detached signature
--list-keys [names] show keys
--fingerprint [names] show fingerprints Please report bugs to <gnupg-bugs@gnu.org>.
[work@work ~]$
gpg (GnuPG) 1.4.1
Copyright (C) 2005 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details. Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512
Compression: Uncompressed, ZIP, ZLIB, BZIP2 Syntax: gpg [options] [files]
sign, check, encrypt or decrypt
default operation depends on the input data Commands: -s, --sign [file] make a signature
--clearsign [file] make a clear text signature
-b, --detach-sign make a detached signature
-e, --encrypt encrypt data
-c, --symmetric encryption only with symmetric cipher
-d, --decrypt decrypt data (default)
--verify verify a signature
--list-keys list keys
--list-sigs list keys and signatures
--check-sigs list and check key signatures
--fingerprint list keys and fingerprints
-K, --list-secret-keys list secret keys
--gen-key generate a new key pair
--delete-keys remove keys from the public keyring
--delete-secret-keys remove keys from the secret keyring
--sign-key sign a key
--lsign-key sign a key locally
--edit-key sign or edit a key
--gen-revoke generate a revocation certificate
--export export keys
--send-keys export keys to a key server
--recv-keys import keys from a key server
--search-keys search for keys on a key server
--refresh-keys update all keys from a keyserver
--import import/merge keys
--card-status print the card status
--card-edit change data on a card
--change-pin change a card's PIN
--update-trustdb update the trust database
--print-md algo [files] print message digests Options: -a, --armor create ascii armored output
-r, --recipient NAME encrypt for NAME
-u, --local-user use this user-id to sign or decrypt
-z N set compress level N (0 disables)
--textmode use canonical text mode
-o, --output use as output file
-v, --verbose verbose
-n, --dry-run do not make any changes
-i, --interactive prompt before overwriting
--openpgp use strict OpenPGP behavior
--pgp2 generate PGP 2.x compatible messages (See the man page for a complete listing of all commands and options) Examples: -se -r Bob [file] sign and encrypt for user Bob
-a, --armor create ascii armored output
-r, --recipient NAME encrypt for NAME
-u, --local-user use this user-id to sign or decrypt
-z N set compress level N (0 disables)
--textmode use canonical text mode
-o, --output use as output file
-v, --verbose verbose
-n, --dry-run do not make any changes
-i, --interactive prompt before overwriting
--openpgp use strict OpenPGP behavior
--pgp2 generate PGP 2.x compatible messages (See the man page for a complete listing of all commands and options) Examples: -se -r Bob [file] sign and encrypt for user Bob
--clearsign [file] make a clear text signature
--detach-sign [file] make a detached signature
--list-keys [names] show keys
--fingerprint [names] show fingerprints Please report bugs to <gnupg-bugs@gnu.org>.
[work@work ~]$
--gen-key 명령어로 공개키를 생성해 보겠습니다.
[work@work ~]$ gpg --gen-key
gpg (GnuPG) 1.4.1; Copyright (C) 2005 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details. gpg: directory `/home/work/.gnupg' created
gpg: new configuration file `/home/work/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/work/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/work/.gnupg/secring.gpg' created
gpg: keyring `/home/work/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection?
gpg (GnuPG) 1.4.1; Copyright (C) 2005 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details. gpg: directory `/home/work/.gnupg' created
gpg: new configuration file `/home/work/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/work/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/work/.gnupg/secring.gpg' created
gpg: keyring `/home/work/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection?
위에 보시다시피 어떤 종류의 키를 사용할 것인지 물어봅니다.
DSA - 디지털 서명 생성 시 사용되는 알고리즘. 데이터를 직접 암호화 할 수 없는 공개키 방식.
RSA - PKI 표준으로 데이터를 암호화할 때 소인수분해를 이용하여 데이터 암호화
EIgamal - 공개키 암호화 방식. 디지털 서명과 데이터 암호화 알고리즘
바로 엔터 쳐서 디폴트 값인 DSA and Elgamal 방식을 선택합니다.
키 사이즈를 물어봅니다. 그냥 엔터 치고 넘어 갑니다.
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
키의 유효 기간을 입력해야 됩니다. 3m이라 입력하여 3개월로 지정합니다.
Requested keysize is 2048 bits
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) 3m
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) 3m
현재로부터 3개월 이후의 날짜와 시각 정보를 확인시켜 주며 올바른지 다시 물어봅니다. 이상 없으니 y입력
Key expires at Tue 19 Jun 2007 02:27:27 AM KST
Is this correct? (y/N)
Is this correct? (y/N)
먼저 키를 식별할 수 있는 User ID를 설정하라고 합니다.
5글자 이상으로 입력해야 됩니다. 저는 itbank라고 입력했습니다.
이메일 주소는 User ID@localhost.localdomain 형태로 입력하면 되겠죠.
저의 경우는 itbank@work.linux.com이 되겠습니다.
코멘트는 공란으로 두어도 상관 없습니다. 그냥 엔터 칩니다.
마지막으로 (O)kay를 위해 O 입력하고 엔터.
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>" Real name: itbank
Email address: itbank@work.linux.com
Comment:
You selected this USER-ID:
"itbank <itbank@work.linux.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>" Real name: itbank
Email address: itbank@work.linux.com
Comment:
You selected this USER-ID:
"itbank <itbank@work.linux.com>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
이제 실제로 쓸 공개키를 생성하게 됩니다. 저는 12345로 입력했습니다. 문자를 조합하여 아무거나 입력해도 상관없습니다. 재입력을 요구하면 똑같이 입력해줍니다. 여기에 입력한 값을 pgp가 랜덤하게 암호화 변수를 적용해 공개키를 만드는 것입니다.
Enter passphrase: 12345
그러면 아래와 같이 재미있는 순서가 등장합니다.
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.
+++++++++++++++++++++++++++++++++++..++++++++++++++++++++++++++++++++++++++++++++++++++.d++++++++++++++++++++.+++++++++++++++++++++++++>++++++++s++....d.....as....d++++q+
wdqweedqwdqwoieo12uifhnd;lknaslfjo3i1ujrlkjnew;lkqmn
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 283 more bytes)
f;kjredawtrpoiewjlfjagdlsj;jnfd;ljnfoi24u09r j;lkqwjflkje;kwljaf;lkjds;flkja;kljew9ri[23ujrkljf;klje;lkesdj;lkajt0[uj2j3tl;jelkasjd;lj;lkjvjdkfsA;LDJIOQ;Jwrdfkjs; dfoi3u2u940-93u5yhrioxzjW[09GR C-UJ5RJMPEFCKDLAJSF90ECU]=4-012 JW'zopcjfePOUQC0-9NU1[JM32RLKEJNFAo wh083U1 AS OIHRFD EW8YUCDHSANLJVEC 0RUJCR 3OQnkwlndlkjha98uyhj4klj1029u`ji lkrehqlkjwh 8yd^[[11~y12097erudwhqijx09dujrkljqiohfawpeohnpdghnhj89tu4io3We 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.
++++++++++..++++++++++++++++++++++++++++++.++++++++++e++++++++++++j+++r.+++++++++++++++.+++++..f+++++..++++++++++.++++++++++++++++++++....+++++++++++++++++++++++++>..++++++++++..............................>+++++..........................+++++^dsl;fkjpoq4wkje;lfka;led^-05rl4rl;femdw;lakl;^k;l
gpg: /home/work/.gnupg/trustdb.gpg: trustdb created
gpg: key B288D045 marked as ultimately trusted
public and secret key created and signed. gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2007-06-18
pub 1024D/B288D045 2007-03-20 [expires: 2007-06-18]
Key fingerprint = AB9E 54A4 2531 6CE1 E3D0 3214 0691 9064 B288 D045
uid itbank <itbank@work.linux.com>
sub 2048g/D6534495 2007-03-20 [expires: 2007-06-18] [work@work ~]$
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.
+++++++++++++++++++++++++++++++++++..++++++++++++++++++++++++++++++++++++++++++++++++++.d++++++++++++++++++++.+++++++++++++++++++++++++>++++++++s++....d.....as....d++++q+
wdqweedqwdqwoieo12uifhnd;lknaslfjo3i1ujrlkjnew;lkqmn
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 283 more bytes)
f;kjredawtrpoiewjlfjagdlsj;jnfd;ljnfoi24u09r j;lkqwjflkje;kwljaf;lkjds;flkja;kljew9ri[23ujrkljf;klje;lkesdj;lkajt0[uj2j3tl;jelkasjd;lj;lkjvjdkfsA;LDJIOQ;Jwrdfkjs; dfoi3u2u940-93u5yhrioxzjW[09GR C-UJ5RJMPEFCKDLAJSF90ECU]=4-012 JW'zopcjfePOUQC0-9NU1[JM32RLKEJNFAo wh083U1 AS OIHRFD EW8YUCDHSANLJVEC 0RUJCR 3OQnkwlndlkjha98uyhj4klj1029u`ji lkrehqlkjwh 8yd^[[11~y12097erudwhqijx09dujrkljqiohfawpeohnpdghnhj89tu4io3We 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.
++++++++++..++++++++++++++++++++++++++++++.++++++++++e++++++++++++j+++r.+++++++++++++++.+++++..f+++++..++++++++++.++++++++++++++++++++....+++++++++++++++++++++++++>..++++++++++..............................>+++++..........................+++++^dsl;fkjpoq4wkje;lfka;led^-05rl4rl;femdw;lakl;^k;l
gpg: /home/work/.gnupg/trustdb.gpg: trustdb created
gpg: key B288D045 marked as ultimately trusted
public and secret key created and signed. gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2007-06-18
pub 1024D/B288D045 2007-03-20 [expires: 2007-06-18]
Key fingerprint = AB9E 54A4 2531 6CE1 E3D0 3214 0691 9064 B288 D045
uid itbank <itbank@work.linux.com>
sub 2048g/D6534495 2007-03-20 [expires: 2007-06-18] [work@work ~]$
랜덤 byte를 발생시키기 위해 키보드를 난타한다든지 마우스를 휘저으라고 요구하네요. 까짓 거 해 주는 겁니다.
이것도 좀 성의가 없으면
Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 283 more bytes)
the OS a chance to collect more entropy! (Need 283 more bytes)
라는 메시지를 띄웁니다. 더 열심히 키보드를 난타한 뒤에 조금 기다려 보면 공개키 생성 작업이 완료됩니다. 걸리는 시간은 시스템 사양에 따라 차이가 있을 수 있습니다.
그럼 생성된 공개키는 어디에 있느냐?
[work@work ~]$ ls -la
total 32
drwxr-xr-x 3 work work 4096 Mar 21 02:51 .
drwxr-xr-x 3 root root 4096 Mar 21 01:55 ..
-rw------- 1 work work 1281 Mar 21 02:51 .bash_history
-rw-r--r-- 1 work work 24 Mar 21 01:55 .bash_logout
-rw-r--r-- 1 work work 191 Mar 21 01:55 .bash_profile
-rw-r--r-- 1 work work 124 Mar 21 01:55 .bashrc
drwx------ 2 work work 4096 Mar 21 02:30 .gnupg
[work@work ~]$
total 32
drwxr-xr-x 3 work work 4096 Mar 21 02:51 .
drwxr-xr-x 3 root root 4096 Mar 21 01:55 ..
-rw------- 1 work work 1281 Mar 21 02:51 .bash_history
-rw-r--r-- 1 work work 24 Mar 21 01:55 .bash_logout
-rw-r--r-- 1 work work 191 Mar 21 01:55 .bash_profile
-rw-r--r-- 1 work work 124 Mar 21 01:55 .bashrc
drwx------ 2 work work 4096 Mar 21 02:30 .gnupg
[work@work ~]$
.gnupg 디렉토리 안에 있습니다. 숨김 디렉토리로 되어 있죠.
[work@work ~]$ ls -la .gnupg/
total 36
drwx------ 2 work work 4096 Mar 21 02:30 .
drwxr-xr-x 3 work work 4096 Mar 21 02:51 ..
-rw------- 1 work work 8084 Mar 21 02:24 gpg.conf
-rw------- 1 work work 1172 Mar 21 02:30 pubring.gpg
-rw------- 1 work work 1172 Mar 21 02:30 pubring.gpg~
-rw------- 1 work work 600 Mar 21 02:30 random_seed
-rw------- 1 work work 1321 Mar 21 02:30 secring.gpg
-rw------- 1 work work 1280 Mar 21 02:30 trustdb.gpg
[work@work ~]$
total 36
drwx------ 2 work work 4096 Mar 21 02:30 .
drwxr-xr-x 3 work work 4096 Mar 21 02:51 ..
-rw------- 1 work work 8084 Mar 21 02:24 gpg.conf
-rw------- 1 work work 1172 Mar 21 02:30 pubring.gpg
-rw------- 1 work work 1172 Mar 21 02:30 pubring.gpg~
-rw------- 1 work work 600 Mar 21 02:30 random_seed
-rw------- 1 work work 1321 Mar 21 02:30 secring.gpg
-rw------- 1 work work 1280 Mar 21 02:30 trustdb.gpg
[work@work ~]$
그러나 위 파일들이 공개키로 그대로 쓸 수 있는 상태는 아닙니다. 특정 파일로 export 시켜야 합니다.
[work@work ~]$ gpg --export -o pub.key
[work@work ~]$ ls
pub.key
[work@work ~]$
[work@work ~]$ ls
pub.key
[work@work ~]$
파일명을 pub.key로 하여 추출했습니다. 파일명은 아무거나 해도 상관없습니다.
근데 위 방법은 바이너리 코드 형태로 추출한 것입니다. 바이너리 코드는 0과 1의 조합으로 구성되어 있기 때문에 편집기로 열어 보면 뭐가 뭔지 도무지 알아 볼 수 없습니다. 그래서 인터넷 상에 공개키를 유포하여 소스 파일의 무결성 검사 용도로 사용할 수 있게 하기 위해 아스키 코드로 공개키를 추출하게 됩니다.
아스키 코드 형태로 추출하고 싶으면 아래와 같이 옵션을 줍니다.
[work@work ~]$ gpg --export -ao pub.key
File `pub.key' exists. Overwrite? (y/N) y
[work@work ~]$
File `pub.key' exists. Overwrite? (y/N) y
[work@work ~]$
이미 바이너리 형태로 추출을 한 번 했기 때문에 덮어씌운다고 물어 보죠. y치고 엔터.
pub.key 파일을 열어 보면 아래와 같이 나오게 되죠.
우리가 알아 볼 수 있는 숫자와 알파벳 문자 조합으로 되어 있는 것을 알 수 있습니다.
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.1 (GNU/Linux) mQGiBEYBAIYRBACPKOGSeg6bUQ19OkwzcKatgZjZ2TrbprDCgvr/3YAL+Jr87etM
ns+pvWlbPep33Vf69+75X7T8llaWUQ4nyeC4VkevDSNUrWA13vPzfyqGPoSJ9dG/
86+bxsa0cAk9pOuWU2SWGjk0A4e3wR/0T1spMHUJrCv3bKX9NoBwOZ0R7wCg/qG8
4jJ79meZnOT0MbBEEUheB6sD/AqKG07mhr5vdmRpsDntVbmrsB3h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K0QCADormsEuqa9Z13v
yapxD6CunBTsCoA+T4FmN6R8VhZTq6Iea6E/hpGzOyh5PTzACSfJXi6rR3yM7IM8
gmzo/YqQ9Lnp7KaPwkHeOKKUYfIbmarUd3PImYWZrnBFhHZR5dGRZAexVFKhIjDT
V1sFqkw+/1SaMjOl8opmmUih/azI90abv1lOQWb0rqx6CqhzgEyk0EbQoaIBsWx7
tT2ijiOuq2r400kljCHKsHWAmVzJZGJqF/YzzINDT+klXASL9GzinPA6MSHvKkQY
qX1KHcGnYwEThr81TC+8HeMifrBcBXeHUW17UYmsJTv2A6SprC+dnK1pvkE0H4wA
chWeym83AAMHB/9iYFbAnn0Z7/PuXOTPNW2otjTH4GxNeAKbv6qWuzBeMMGfOuj1
ppApvYRZkpJnAKxQ//yYDXIV08Hq4puFVSApJiz058GkTHPIKhZsrvbdfnrEp3Zt
fUU8MSkq3a+95CJETq9ZfzYfQfGocys7CtLTHdhEnSF9wDCVPk8jLP8Xd7gQ3GxA
XZCFLdHcNYnJjA0DRT63OG1/S9LVtS/75jqDoPfrrDx18rEpnii8nxlSd+LbggNY
8vkzW9WTPmKzChAkutL5+qJox365Y8we/Xltrqvd8Sf7sG559fQdNDF0Xu8uLAgW
x3rBJ99kZnaFo8rCx9fYb1ziuWJunemUrm03iE8EGBECAA8FAkYBAK0CGwwFCQB2
pwAACgkQFyEY1WYDG8WFgACfe0GzdGeMDg4QeS2/q6TU9hmjZG0An04wcikUam4A
ZpWO4R/FPXBUvpSD
=qsuu
-----END PGP PUBLIC KEY BLOCK-----
그럼 생성된 공개키를 serv컴에서 쓸 수 있도록 serv컴으로 전송해 주면 되겠죠. serv의 serv계정 홈 디렉토리로 전송합니다.
serv의 IP는 192.168.10.120 입니다.
[work@work ~]$ scp pub.key serv@192.168.10.120:
The authenticity of host '192.168.10.120 (192.168.10.120)' can't be established.
RSA key fingerprint is d3:98:b7:05:67:8e:a1:b8:0b:22:de:e4:bb:a4:af:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.120' (RSA) to the list of known hosts.
serv@192.168.10.120's password:
pub.key 100% 1690 1.7KB/s 00:00
[work@work ~]$
The authenticity of host '192.168.10.120 (192.168.10.120)' can't be established.
RSA key fingerprint is d3:98:b7:05:67:8e:a1:b8:0b:22:de:e4:bb:a4:af:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.120' (RSA) to the list of known hosts.
serv@192.168.10.120's password:
pub.key 100% 1690 1.7KB/s 00:00
[work@work ~]$
이제 serv로 이동해서 공개키 작업을 마무리하도록 합시다.
serv의 serv 계정 홈디렉토리에 pub.key 파일이 잘 도착해 있는지 봅시다.
[serv@serv ~]$ ls
pub.key
[serv@serv ~]$
pub.key
[serv@serv ~]$
잘 도착했군요. 이제 이 공개키를 serv 계정에서 사용할 수 있도록 import 시킵니다.
[serv@serv ~]$ gpg --import pub.key
gpg: key 66031BC5: "itbank <itbank@work.linux.com>" not changed
gpg: Total number processed: 1
gpg: unchanged: 1
[serv@serv ~]$
gpg: key 66031BC5: "itbank <itbank@work.linux.com>" not changed
gpg: Total number processed: 1
gpg: unchanged: 1
[serv@serv ~]$
공개키 작업은 이걸로 완료되었습니다. 이제 serv의 serv계정은 work의 work계정 공개키를 사용할 수 있는 상태가 되었습니다. 따라서 serv컴의 serv계정에서 메일을 작성하여 gpg로 암호화시켜 work컴의 work계정으로 전송하면 이 암호화된 메일을 work는 자신의 개인키로 복호화시켜 볼 수 있다는 겁니다. 자신의 공개키로 암호화된 메일이니 자신의 개인키로 복호화시킬 수 있는 것이죠.
serv에서 간단한 텍스트 파일을 만들어 work로 메일 전송해 보겠습니다.
아래 내용을 담은 paper.txt 파일을 생성했습니다.
Hi, Work!!! 1+1=2
2+3=5
10+10=20
2+3=5
10+10=20
암호화 하기 전 encrypt 옵션을 먼저 확인해 봅니다.
[serv@serv ~]$ gpg --help | grep encrypt
sign, check, encrypt or decrypt
-e, --encrypt encrypt data
-c, --symmetric encryption only with symmetric cipher
-r, --recipient NAME encrypt for NAME
-se -r Bob [file] sign and encrypt for user Bob
[serv@serv ~]$
sign, check, encrypt or decrypt
-e, --encrypt encrypt data
-c, --symmetric encryption only with symmetric cipher
-r, --recipient NAME encrypt for NAME
-se -r Bob [file] sign and encrypt for user Bob
[serv@serv ~]$
공개키의 속성도 확인해 보겠습니다. 지금은 공개키를 하나만 import 시켜 두었기 때문에 아래처럼 하나의 공개키 정보만 출력됩니다.
[serv@serv ~]$ gpg --list-key
/home/work/.gnupg/pubring.gpg
-----------------------------
pub 1024D/B288D045 2007-03-20 [expires: 2007-06-18]
uid itbank <itbank@work.linux.com>
sub 2048g/D6534495 2007-03-20 [expires: 2007-06-18] [serv@serv ~]$
/home/work/.gnupg/pubring.gpg
-----------------------------
pub 1024D/B288D045 2007-03-20 [expires: 2007-06-18]
uid itbank <itbank@work.linux.com>
sub 2048g/D6534495 2007-03-20 [expires: 2007-06-18] [serv@serv ~]$
그럼 이 paper.txt 파일을 gpg로 암호화시켜 봅니다.
[serv@serv ~]$ gpg -e -r itbank@work.linux.com paper.txt
[serv@serv ~]$ ls
paper.txt paper.txt.gpg pub.key
[serv@serv ~]$ ls
paper.txt paper.txt.gpg pub.key
이메일 주소를 기입한 'itbank' <- 요 부분은 gpg --list-key 명령어로 확인했던 공개키 ID로 직접 입력해줘도 됩니다. 'B288D045'이라고 입력해도 된다는 얘기이죠.
이 암호화된 paper.txt.gpg 파일을 work로 전송하여 work에서 자신의 개인키로 암호를 복호화하여 열어 보면 되는 겁니다. work 의 IP는 192.168.10.130입니다.
[serv@serv ~]$ scp paper.txt.gpg work@192.168.10.130:
serv@192.168.10.130's password:
paper.txt.gpg 100% 633 0.6KB/s 00:00
[serv@serv ~]$
serv@192.168.10.130's password:
paper.txt.gpg 100% 633 0.6KB/s 00:00
[serv@serv ~]$
work로 이동합니다.
[work@work ~]$ ls
paper.txt.gpg pub.key
[work@work ~]$
paper.txt.gpg pub.key
[work@work ~]$
paper.txt.gpg 파일을 그냥 열어 보면 정체를 알 수 없는 형태로 되어 있죠. 이제 이걸 복호화해 봅니다.
Enter passphrase 를 물어보죠. 맨 처음 work에서 공개키를 만들 때 입력했던 값인 12345를 넣어주면 됩니다.
[work@work ~]$ gpg -d paper.txt.gpg
You need a passphrase to unlock the secret key for
user: "itbank <itbank@work.linux.com>"
2048-bit ELG-E key, ID FCD799AE, created 2007-03-21 (main key ID 66031BC5) Enter passphrase:
You need a passphrase to unlock the secret key for
user: "itbank <itbank@work.linux.com>"
2048-bit ELG-E key, ID FCD799AE, created 2007-03-21 (main key ID 66031BC5) Enter passphrase:
짜잔!! 복호화되었습니다. ^^
gpg: encrypted with 2048-bit ELG-E key, ID FCD799AE, created 2007-03-21
"itbank <itbank@work.linux.com>"
Hi, Work!!! 1+1=2
2+3=5
10+10=20
[work@work ~]$
"itbank <itbank@work.linux.com>"
Hi, Work!!! 1+1=2
2+3=5
10+10=20
[work@work ~]$