GPG

Материал из poiuty wiki
Перейти к: навигация, поиск

Установим пакеты.

apt-get install gnupg

Создадим приватный и публичный ключ.

# gpg --gen-key
gpg (GnuPG) 1.4.18; Copyright (C) 2014 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) 4096
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: Ivan Ivanov
Email address: ivan@ivanov
Comment: 
You selected this USER-ID:
    "Ivan Ivanov <ivan@ivanov>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
Enter passphrase:
Repeat passphrase:
Repeat passphrase:
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.
...+++++
................................+++++
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 33E01A68 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   4096R/33E01A68 2017-03-09
      Key fingerprint = 1018 5760 90B5 151D 773F  CEC9 C516 8572 33E0 1A68
uid                  Ivan Ivanov <ivan@ivanov>
sub   4096R/233E8E8C 2017-03-09

Создадим отзывающий сертификат. Сохраните его в надежном месте и не передавайте никому.

# gpg --output revoke.asc --gen-revoke -a "Ivan Ivanov <ivan@ivanov>"

sec  4096R/33E01A68 2017-03-09 Ivan Ivanov <ivan@ivanov>

Create a revocation certificate for this key? (y/N) y
Please select the reason for the revocation:
  0 = No reason specified
  1 = Key has been compromised
  2 = Key is superseded
  3 = Key is no longer used
  Q = Cancel
(Probably you want to select 1 here)
Your decision? 0
Enter an optional description; end it with an empty line:
> 
Reason for revocation: No reason specified
(No description given)
Is this okay? (y/N) y

You need a passphrase to unlock the secret key for
user: "Ivan Ivanov <ivan@ivanov>"
4096-bit RSA key, ID 33E01A68, created 2017-03-09

Enter passphrase:

You need a passphrase to unlock the secret key for
user: "Ivan Ivanov <ivan@ivanov>"
4096-bit RSA key, ID 33E01A68, created 2017-03-09

Revocation certificate created.

Please move it to a medium which you can hide away; if Mallory gets
access to this certificate he can use it to make your key unusable.
It is smart to print this certificate and store it away, just in case
your media become unreadable.  But have some caution:  The print system of
your machine might store the data and make it available to others!

Посмотреть список публичных ключей.

gpg --list-keys

Посмотреть список приватных ключей.

gpg --list-secret-keys

Экспорт публичного ключа. Публичный ключ можно разместить в свободном доступе (https://keybase.io/, https://pgp.mit.edu, http://github.com).

gpg --export -a "Ivan Ivanov <ivan@ivanov>" # напишет в консоль
gpg --export -a "Ivan Ivanov <ivan@ivanov>" > public.key # сохранит в файл

Экспорт приватного ключа. Никому не раскрывайте эту информацию.

gpg --export-secret-key -a "Ivan Ivanov <ivan@ivanov>" > private.key

Удалить публичный ключ.

gpg --delete-key "Ivan Ivanov <ivan@ivanov>"

Удалить приватный ключ.

gpg --delete-secret-key "Ivan Ivanov <ivan@ivanov>"

Импорт ключей.

gpg --import public.key
gpg --import private.key

Применение

1. Зашифруем файл => расшифруем.

echo "test" > secret.txt
gpg --trust-model always --encrypt --armor --recipient "Ivan Ivanov <ivan@ivanov>" secret.txt 
gpg secret.txt.asc

Все кого вы указали --recipient Name => смогут расшифровать файл.
Ваши действия => добавляем чужой публичный ключ => шифруем => отправляем зашифрованный файл.

wget https://raw.githubusercontent.com/poiuty/keys/master/poiuty.gpg
gpg --import poiuty.gpg
gpg --trust-model always --encrypt --armor --recipient "Ivan Ivanov <ivan@ivanov>" --recipient "poiuty <poiuty@lepus.su>" secret.txt


2. Подпишем текст => создаем текстовый файл => подписываем.

echo "test" > test.txt
gpg --clearsign test.txt

Другие могут добавить ваш приватный ключ и проверить подпись.

# gpg --verify test.txt.asc 
gpg: Signature made Thu 09 Mar 2017 17:06:13 CET using RSA key ID 33E01A68
gpg: Good signature from "Ivan Ivanov <ivan@ivanov>"

Если вы добавили свой ключ на keybase.io => можно воспользоваться онлайн проверкой https://keybase.io/verify
4969bea3900c6390be687a0fe93733a8.png

Links

https://www.gnupg.org/documentation/manpage.html
http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/gpg-cs.html
https://fedoraproject.org/wiki/Creating_GPG_Keys/ru
https://www.opennet.ru/base/sec/gpg_crypt.txt.html