RSS구독하기:SUBSCRIBE TO RSS FEED
즐겨찾기추가:ADD FAVORITE
글쓰기:POST
관리자:ADMINISTRATOR

출처 : 대전국제IT교육센터 정성재 강사

 

1. gpg 사용하기
(1) 사용법
   gpg [options] command
(2) command
   --gen-key : 새로운 공개키와 비밀키를 생성한다.
   --list-keys : 설치된 공개키의 리스트를 보여준다.
   --export : 공개키를 다른 사람에게 전달하기 위해서 파일의 형태로 만들어 준다. 기본적으로
              바이너리형태로 만든다. 이 다음에 오는 키의 이름은 위에 생성된 키생성시 입력한
              문자열의 일부나 전체를 사용하도록 한다.
   --import! : 다른 사람의 공개키를 가지고 자신의 gpg에 설치한다.
   --edit-key : 키에 대하여 사인(sign)등의 편집을 한다.
   --encrypt, -e : 자료를 암호화한다.
(3) options
   --outfile 파일명 : '파일명'으로 공개키가 들어있는 파일을 생성한다. 보통 --export와 같이 사용
                    되며 이 옵션을 사용하지 않으면 화면으로 출력으로 출력한다.
   --armor , -a    : 공개키를 ASCII형으로 만든다.
   --encrypt : 암호화하는 옵션이다.
   --recipient : 암호화하는 옵션인 --encrypt과 같이 쓰이며 받는 사람의 공개키를 적는다.
   --decrypt : 해독화하는 옵션이다.
(4) 사용예
   1) [posein@www posein]$ gpg --output sungjae.gpg --armor --export sungjae
       => 공개키를 sungjae라고 생성하고 sungjae.gpg라는 파일로 저장한다.
   2) [prehee@www prehee]$ gpg --armor --import! sungjae.gpg
       => sungjae.gpg라는 공개키를 자신의 gpg에 설치한다. --armor옵션은 텍스트형태의 파일을
         import!할 경우를 뜻한다.
   3) [prehee@www prehee]$ gpg --edit-key sungjae


2. gpg의 설정
(1) 공개키와 비밀키를 생성한다.
   [posein@www posein]$ gpg --gen-key
   gpg (GnuPG) 1.0.6; Copyright (C) 2001 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: Warning: using insecure memory!
   Please select what kind of key you want:
      (1) DSA and ElGamal (default)
      (2) DSA (sign only)
      (4) ElGamal (sign and encrypt)
   Your selection?
    => (설명) gpg에서는 위와 같은 키방식을 제공하는데 DSA는 서명만 할 수 있는 방식이고 EIGamal
            은 암호화를 할 수 있는 방식이다. 일반적으로 디폴트값을 사용하면 되므로 엔터키를
            치고 다음으로 넘어간다.

   DSA keypair will have 1024 bits.
   About to generate a new ELG-E keypair.
                 minimum keysize is  768 bits
                 default keysize is 1024 bits
       highest suggested keysize is 2048 bits
   What keysize do you want? (1024)
    => (설명) 키의 길이를 정하는 것이다. 물론 크기가 클수록 안전하지만, 암호화하고 해독하는데
             많은 시간이 걸린다. 이 부분도 디폴트값으로 한다.
   Requested keysize is 1024 bits
    => (설명) 1024bit로 키의 크기가 설정되었다.
   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)
    => (설명) 키의 유효기간을 지정하는 것이다. 중요한 것일 경우에는 유효기간을 짧게 잡아서 키를
            자주 변경하는 것이 좋다. 이 부분도 디폴트값으로 한다. 즉 유효기간이 없다.
   Key does not expire at all
    => (설명) 유효기간이 설정되지 않음을 나타낸다.
   Is this correct (y/n)? y
    => (설명) 정확히 맞는지 여부를 묻는 부분이다.
   You need a User-ID to identify your key; the software constructs the user id
   from Real Name, Comment and Email Address in this form:
       "Heinrich Heine (Der Dichter) <
heinrichh@duesseldorf.de>"

   Real name: Jung Sung-jae
    => (설명) 키의 이름을 정하는 부분이다. 보통 자신의 이름을 적는다.
   Email address:
posein@korea.com
    => (설명) 자신의 전자우편 주소를 쓴다.

   Comment: system manager
    => (설명) 설명한 것이 있으면 적도록 한다.
   You selected this USER-ID:
       "Jung Sungjae (system manager) <
posein@korea.com>"
   Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
    => (설명) 위와같이 생성이 되며 변경할 사항이 없으면 o를 누른다.
   You need a Passphrase to protect your secret key.
    => 비밀키 보호용 암호를 설정한다.
  
   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.
   .++++++++++++++++++++.+++++++++++++++++++++++++.+++++...+++++.++++++++++.++++++++++.+++++
   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.
   .+++++++++++++++++++++++++++++++++++.++++++++++++++++++++.++++++++++++++++++++++++++++++++
   public and secret key created and signed.
    => (설명) 공개키와 비밀키를 생성하였다.
(2) 생성된 키의 확인
   1) 설치된 디렉토리의 확인
     [posein@www posein]$ ls -a
     ./   .bash_history  .bash_profile  .emacs   .kde/      .mysql_history  .viminfo 
     ../   bash_logout   .bashrc        .gnupg/  .mplayer/  .screenrc       .wl      
       => .gnupg라는 디렉토리가 생성되었음을 알 수 있다.
   2) 설치된 디렉토리내의 파일
     [posein@www posein]$ cd .gnupg
     [posein@www .gnupg]$ ls
     options  pubring.gpg  pubring.gpg~  random_seed  secring.gpg
   3) 설치된 공개키의 리스트 확인
     posein@www posein]$ gpg --list-keys
     gpg: Warning: using insecure memory!
     /home/posein/.gnupg/pubring.gpg
     -------------------------------
     pub  1024D/7F1400E1 2002-04-11 Jung sungjae (system manager) <
posein@korea.com>

     sub  1024g/C4E2C936 2002-04-11

3. 공개키 파일의 생성과 설치

(1) 공개키 파일 만들기
   1) [posein@www posein]$ gpg --armor --export sungjae
      gpg: Warning: using insecure memory!
      -----BEGIN PGP PUBLIC KEY BLOCK-----
      Version: GnuPG v1.0.6 (GNU/Linux)
      Comment: For info see http://www.gnupg.org

      mQGiBDy1VWIRBACyHe0EnIe7payoWcNRSDwc/SLSL8pZ7kIrkPlnv6P3tARJN0xU
      s/C+kBLhB3JCN0N/7HO8QL82tcZFGQX0RStEzjp4DxIDFRZCcxq6AQdmoCW+FYxV
      p4mBpSheoNzw3sOumviHSiuo8qCUFY1/NSInvTJJzcgcBhHeoNbSEEKrFwCgzCrq
      1J8kvQG10j51mKu9iRFbq3UD/2icBWGRnQ+oWSUZAEvodjn560uobpxe2Py6jwlJ
      NCwv+dLFJV2MX1e4faRU5yfDF0O43IlgO8gjiA4whi8GuDzgVbVJsTWcrlZjusmw
      fj4wlelNXm/KahYfuTsWCusAQDBpUCDKjmUY9ocxf5aaSscQMXVexs5Q7TZNSsG5
      yFtZA/9Qcng02Auizqz5aOysmU2UuGEanbK+TR0dGe2FHw4hV7fCWVqsj5Q7h/sj
      +pCDWQp9oCZUA6WoFUWXAeHRXZ9Cl9bOMmiBAtcqxdo1Sy02d0RgC+esrubEPXrR
      cMkJSpIfHEZrHInZQjUw8qOB9o1N3itGFCpCWoHLhug7Ol3N3bQic3VuZ2phZSAo
      bGludXgpIDxwb3NlaW5Aa29yZWEuY29tPohXBBMRAgAXBQI8tVViBQsHCgMEAxUD
      AgMWAgECF4AACgkQbR8Td38UAOFL/wCfUxSvPnjrh6MPJA9q18qIsrR3wVQAniCM
      vftp1iqSWnFkRtC2yMK3FSaOuQENBDy1VWMQBACL+zeYup7TTWiaV4wooqRVXAdd
      8BvxoA6hfyTFXCvpqsbXAoy/3dbBY/bqhf9sJdE7ksVTjHd1o2aD7eDzkr2hzLC8
      x/NkBh+PcgiaqJR9APBSroW5ySr0PF6XfWHIgvgF00+Luu4GpqrXEdIh6SxImXm3
      2EF6xBukjCjxCDG3LwADBQP/QPOzqGmSrlNClp4aWrh7Q9xdQLLx9hW62hmsApT4
      /CG2wp7gDDshts+nwltw3+4LLp6j2MOP2bPoakbXcIBnW457gpZmsbyyFRwmmYqW
      WjFR3DDLmxeeX0Pqb8kNgUTCf31cgRDdUjQM0JdcE8kfM1pzFLjsk8umND6oqaB4
      waSIRgQYEQIABgUCPLVVYwAKCRBtHxN3fxQA4XABAJ0cSqKUNMWehupuoItg+qZd
      GYxFmACfRfHzc+aZ2jDdYZdBKZ8AczR1OwY=
      =c2ma
      -----END PGP PUBLIC KEY BLOCK-----
       => (설명) --output옵션을 붙여 주지 않았다면 결과가 표준출력인 화면으로 나타나다. 이
                텍스트 결과를 전자 메일로 전송해 준다거나 홈페이지에 올리게 되면 다른 사람들이
                이 공개키를 가지고 지정된 사람들만이 볼 수 있는 비밀 문서를 보낼 수 있게 된다.
   2) [posein@www posein]$ gpg --output sungjae.gpg --armor --export sungjae
       => sungjae.gpg라는 공개키를 생성한다.
(2) 다른 사람의 공개키 설치하기
   1) 다른 사람의 공개키를 설치
     [prehee@www prehee]$ gpg --armor --import! sungjae.gpg
     gpg: Warning: using insecure memory!
     gpg: key 21BCE5C8: public key import!ed
     gpg: /home/prehee/.gnupg/trustdb.gpg: trustdb created
     gpg: Total number processed: 1
     gpg:               import!ed: 1
      => (설명) sungjae.gpg는 sungjae라는 사람의 공개키가 들어있는 파일이고, 텍스트 파일형태이
              므로 --armor옵션을 사용하였다. 참고로 처음으로 gpg를 실행시키면 디렉토리와 관련
              파일을 먼저 생성하므로 다시 한번 명령을 내려야 한다.
   2) 설치된 공개키의 확인
     [prehee@www prehee]$ gpg --list-keys
     gpg: Warning: using insecure memory!
     /home/prehee/.gnupg/pubring.gpg
     -------------------------------
     pub  1024D/67667253 2002-04-11 prehee (system tester) <
prehee@mybestone.com>
     sub  1024g/F1FB95A8 2002-04-11

     pub  1024D/21BCE5C8 2002-04-11 Jung sungjae (system) <
posein@korea.com>
     sub  1024g/F5F740F4 2002-04-11
      => 다른 사람의 공개키를 잘 이용하려면 자신의 비밀키를 위와 같이 미리 생성해야 한다.

   3) 다른 사람 공개키가 서명달기
      [prehee@www prehee]$ gpg --edit-key sungjae
      gpg (GnuPG) 1.0.6; Copyright (C) 2001 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: Warning: using insecure memory!

      pub  1024D/21BCE5C8  created: 2002-04-11 expires: never      trust: -/q
      sub  1024g/F5F740F4  created: 2002-04-11 expires: never
      (1). Jung sungjae (system manager) <
posein@korea.com>
      Command>
        => (설명) 공개키의 편집을 위한 상태로 진입한다.

      Command> fpr
      pub  1024D/21BCE5C8 2002-04-11 sungjae (linux) <
posein@korea.com>

                   Fingerprint: A20D 6C76 1919 4FCF 5A57  2BE2 BBE2 67FC 21BC E5C8
       => (설명) 공개키의 지문(fingerprint)을 확인할 수 있다. Fingerprint라는 말 뒤에 나오는
                16진수의 숫자들이 이 공개키의 지문이다. 이 지문을 공개키 주인과 연락하면서
                (전화등으로 연락하면 서로 지문을 비교) 확인할 수 있다. 이렇게 확인을 거치면
                sign명령으로 sungjae의 공개키에 나의 서명을 할 수 있다.
      Command> sign

      pub  1024D/21BCE5C8  created: 2002-04-11 expires: never      trust: -/q
                   Fingerprint: A20D 6C76 1919 4FCF 5A57  2BE2 BBE2 67FC 21BC E5C8

           Jung sungjae (system manager) <
posein@korea.com>

      Are you really sure that you want to sign this key
      with your key: "prehee (system tester) <
prehee@mybestone.com>"

      Really sign? y

      You need a passphrase to unlock the secret key for
      user: "prehee (system tester) <
prehee@mybestone.com>"
      1024-bit DSA key, ID 67667253, created 2002-04-11

      Enter passphrase:
       => 패스워드를 입력하면 서명이 된다.
     
      Command> check
      uid  Jung sungjae (system manager) <
posein@korea.com>
      sig!       21BCE5C8 2002-04-11   [self-signature]
      sig!       67667253 2002-04-11   prehee (system tester) <prehee@mybestone
       => (설명) 결과를 보면 다른 사람의 공개키에 서명을 했어도 자신의 공개키에도 서명이 된다.
               자신의 공개키를 export할 때에는 자동적으로 gpg가 자신의 서명을 해준다.

4. 문서를 암호화하고 해독하기

(1) 개요 : 문서를 특정인에게 보내고 싶을 경우에 문서를 그 사람의 공개키를 이용해서 암호화한
          뒤 그 암호화된 문서를 그 사람이 받게 되면 그 사람은 자신의 공개키로 암호화 된 문서를
          자신의 비밀키로 해독할 수 있다.
(2) 사용예 : prehee라는 사용자가 posein(Jung sungjae)이라는 사용자에게 보내기 위해 암호화함
   1) 암호화
     a. [prehee@www prehee]$ cat a.txt
        I love linux
        I love windows.
         => (설명) 다음과 같은 문서가 있다.
     b. [prehee@www prehee]$ gpg --output en_a.txt --encrypt --recipient sungjae a.txt
        gpg: Warning: using insecure memory!
        => a.txt라는 문서를 암호화하여 en_a.txt라는 파일을 생성한다. --recipient 다음에는
          받는 사람의 공개키 이름을 적는다.
     c. [prehee@www prehee]$ ls
        Desktop/  a.txt  en_a.txt  sungjae.gpg
         => 암호화된 파일이 생성되었다. 일반적인 텍스트확인명령인 cat을 이용해서 살펴보면 깨진
           문자로 표시됨을 알 수 있다.
   2) 해독 : 이 메일등으로 전송됨 파일을 확인해보도록 하자. 암호화된 문서는 본인의 비밀키만을
            이용해서 풀 수 있다.
     a. [posein@www posein]$ ls
        Desktop/  en_a.txt  sungjae.gpg 
         => 암호화된 문서를 전송받았다. cat명령을 이용해서 확인해봐도 알 수가 없다.
     b. [posein@www posein]$ gpg --output a.txt --decrypt en_a.txt
        gpg: Warning: using insecure memory!

        You need a passphrase to unlock the secret key for
        user: "Jung sungjae (system manager) <
posein@korea.com>"
        1024-bit ELG-E key, ID F5F740F4, created 2002-04-11 (main key ID 21BCE5C8)

        gpg: /home/posein/.gnupg/trustdb.gpg: trustdb created
        gpg: encrypted with 1024-bit ELG-E key, ID F5F740F4, created 2002-04-11
        "Jung sungjae (system manager) <
posein@korea.com>"
          => 자신의 비밀키를 이용하여 암호를 입력하면 암호화된 문서 en_a.txt를 a.txt로 해독
            한다.
     c. [posein@www posein]$ ls
        Desktop/  a.txt  en_a.txt  sungjae.gpg 
         => a.txt라는 파일이 생성되었음을 알 수 있다.
     d. [posein@www posein]$ cat a.txt
        I love linux
        I love windows.
         => 정상적인 내용확인이 가능하다.

Trackback
Reply
우주곰:지구곰이 아닙니다.
지구곰이 아닙니다.
Categories (190)
Information (5)
About uzoogom (5)
My Advanced Linux (73)
Learning Linux (96)
OperatingSystem (5)
Databases (4)
OpenSource (1)
Tips! (1)
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30