• gpg 使用入门


    1. 生成秘钥

    gpg --full-generate-key 等价于 gpg --full-gen-key

    image-20211221173837788

    Real name: yellowconvict为该秘钥的名字,也称为 USER-ID

    在生成秘钥前最后一步还需要为秘钥设置密码

    image-20211221173530694

    2. 查看公私钥

    2.1 查看公钥

    gpg --list-key

    image-20211221174526296

    2.2 查看私钥

    gpg --list-secret-key

    image-20211221174541735

    3. 导出公私钥

    --armor: 将其转换为ASCII码显示


    3.1 导出公钥

    gpg --armor --output 文件名 --export 用户ID

    如:

    gpg --armor --output yellowconvict.pub --export yellowconvict


    3.2 导出私钥

    gpg --armor --output 输出文件 --export-secret-keys 用户ID

    gpg --armor --output yellowconvict.pri --export-secret-keys yellowconvict
    导出私钥时需要输入一开始为秘钥设置的密码

    image-20211221182210506

    4. 使用公钥加密文件

    gpg --recipient 用户ID --output 输出文件 --encrypt 原始文件

    image-20211222101605059

    5. 使用私钥解密文件

    gpg --output 输出文件 --decrypt 已加密文件

    image-20211222102001474

    第一次使用私钥解密需要输入为秘钥设置的密码,之后就不需要输入了

    image-20211222101801796

    6. 删除秘钥

    必须先删除私钥,才能删除公钥

    6.1 删除私钥

    gpg --delete-secret-keys yellowconvict


    6.2 删除公钥

    gpg --delete-keys yellowconvict


    7. 其他

    第一次生成秘钥时,可能出现卡住的问题,类似如下提示:

    Not enough random bytes available. Please do some other work to give the OS a chance to collect more
    
    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.
    

    解决方法:

    不要退出当前终端,新建一个终端,并根据系统执行以下命令,命令执行完后,卡住的界面瞬间完成

    Ubuntu:

    $ sudo apt install rng-tools
    $ rng -r /dev/urandom
    

    CentOS:

    $ yum install rng-tools
    $ rngd -r /dev/urandom
    

  • 相关阅读:
    HDU3555:Bomb
    入门OJ:售货员的难题
    Zju1100 Mondriaan
    与图论的邂逅08:树上倍增
    入门OJ:八中生成树2
    Poj2286 The Rotation Game
    P1379 八数码难题
    [SCOI2005]骑士精神
    与图论的邂逅07:K短路
    [Usaco2007 Feb]Cow Party
  • 原文地址:https://www.cnblogs.com/convict/p/15845933.html
Copyright © 2020-2023  润新知