Linux gpg


GNU Privacy Guard (GnuPG or GPG) é uma alternativa GPL ao aplicativo PGP de criptografia. GnuPG é compatível com a RFC 4880, o padrão da IETF para a especificação do OpenPGP. As versões atuais do PGP (e Filecrypt da Veridis) possuem interoperabilidade com o GnuPG e com outros sistemas compatíveis com o OpenPGP. GnuPG é parte da Free Software Foundation e do projeto de software GNU. Além disso, ele recebeu o patrocínio do Governo Alemão: 1 via wikipedia http://pt.wikipedia.org/wiki/GNU_Privacy_Guard

Resumo

Basicamente você cria sua chave, criptografa/descriptografa umas coisas e se quiser que outra pessoa/pc descriptografe algo que você criptografou você precisa mandar sua chave publica pra elas.

Fazendo acontecer

Tudo começa com a criação da sua própria chave, pois isso é que ira definir a sua “assinatura’ para encriptar e decriptar as coisas.

Depois basta lembrar de um mundo de comandos para fazer isso acontecer :)

Gerando Chaves

diego@ragazzid:~$ gpg --gen-key
gpg (GnuPG) 1.4.11; Copyright (C) 2010 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.

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)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
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) 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 the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

Real name: Diego Ragazzi
Email address: d@ragazzid.com.br
Comment: WikiPage - Tuto
You selected this USER-ID:
    "Diego Ragazzi (WikiPage - Tuto) <d@ragazzid.com.br>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.

gpg: gpg-agent is not available in this session
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.

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 279 more bytes)
...+++++
.+++++
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.
.........+++++

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 83 more bytes)
..........+++++
gpg: /home/diego/.gnupg/trustdb.gpg: trustdb created
gpg: key 894DFDC1 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
pub   2048R/894DFDC1 2014-06-09
      Key fingerprint = 3975 71A7 80CF 5AA7 F10E  820B E925 668D 894D FDC1
uid                  Diego Ragazzi (WikiPage - Tuto) <d@ragazzid.com.br>
sub   2048R/1E080A62 2014-06-09
diego@ragazzid:~$ ls -als .gnupg/
total 40
 4 drwx------ 2 diego diego 4096 Jun  9 20:44 .
 4 drwxr-xr-x 3 diego diego 4096 Jun  9 20:38 ..
12 -rw------- 1 diego diego 9398 Jun  9 20:19 gpg.conf
 4 -rw------- 1 diego diego 1210 Jun  9 20:44 pubring.gpg
 4 -rw------- 1 diego diego 1210 Jun  9 20:44 pubring.gpg~
 4 -rw------- 1 diego diego  600 Jun  9 20:44 random_seed
 4 -rw------- 1 diego diego 2588 Jun  9 20:44 secring.gpg
 4 -rw------- 1 diego diego 1280 Jun  9 20:44 trustdb.gpg
diego@ragazzid:~$ gpg --list-keys
/home/diego/.gnupg/pubring.gpg
------------------------------
pub   2048R/894DFDC1 2014-06-09
uid                  Diego Ragazzi (WikiPage - Tuto) <d@ragazzid.com.br>
sub   2048R/1E080A62 2014-06-09

Criptografando alguns arquivos

diego@ubuntusrv:~$ cat ragazzid.com.br
site ragazzid.com.br :):
diego@ubuntusrv:~$ gpg --output ragazzid.com.br.gpg --sign ragazzid.com.br

You need a passphrase to unlock the secret key for
user: "Diego Ragazzi (WikiPage - Tuto) <d@ragazzid.com.br>"
2048-bit RSA key, ID 894DFDC1, created 2014-06-09

gpg: gpg-agent is not available in this session
diego@ubuntusrv:~$ cat ragazzid.com.br.gpg
▒▒▒▒▒▒▒▒R5▒▒▒▒▒A▒5zI▒E▒▒UU▒)z▒▒zIE▒▒<▒▒3KR▒▒▒4▒▒:eX▒▒X▒@▒▒8`fݼ▒▒▒K▒T▒3
▒6Eye▒▒I▒▒▒}▒ŶN▒v▒v▒▒o      
                                          ▒▒Y&θ▒v▒ǹb▒▒K▒
▒^qUk֜^▒x▒▒▒▒▒nKα▒Q▒ɵ[+n▒▒▒u▒$i▒w▒▒lٴ▒▒▒▒z▒▒▒▒▒▒ŵtf▒▒▒r▒f▒̻
▒^▒▒GRp▒W▒▒a▒Yd▒▒▒▒▒▒▒U)▒vݸ▒²▒2▒▒▒▒▒▒▒q▒▒p▒q̂x▒▒K▒▒7~n▒▒{ļ▒▒-W▒\:▒▒▒޺_▒
:▒$▒&]▒t▒r▒▒C{▒▒]Y▒▒d▒O▒▒ޘ?▒▒U▒l▒▒▒Kv<)▒-▒▒+▒r▒R▒▒Y

DesCriptografando alguns arquivos

diego@ubuntusrv:~$ gpg –output ragazzid.com.br –recipient ragazzid.com.br –decrypt ragazzid.com.br.gpg

DesCriptografando alguns arquivos em outra máquina

Para isso, você precisa mandar sua chave privada (o que não é muito recomendável) mas aqui vai:

gpg --export-secret-keys d@ragazzid.com.br > ragazzid.key

Se quiser mandar a sua chave pública para alguém, permitindo a essa pessoa que criptografe arquivos que só você pode abrir, use o comando:

gpg --export d@ragazzid.com.br > ragazzid.pub

Ai a pessoa que receber precisa dar um import

gpg --import arquivo.x

E pronto! Quando se usa o –encrypt o gpg vai procurar a chave pública associada ao que você digitou e o –decrypt procura pela privada :)