gpg2 加密解密
gpg2 加密解密
空灵飞渡 发表于1年前
gpg2 加密解密
  • 发表于 1年前
  • 阅读 31
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   


gpg2 生成秘钥

查看是否安装
rpm-qa│grep gnupg

rpm –ivh gnupg2-2.0.10-6.el5


gpg2 --gen-key
[root@VM_0_178_centos .ssh]# gpg2 --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 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? 
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (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) 
Key does not expire at all
Is this correct? (y/N) 
Key is valid for? (0) 
Key does not expire at all
Is this correct? (y/N) y    ###前面都缺省就行,这样选择yes

GnuPG needs to construct a user ID to identify your key.

Real name: VM_0_178_centos     ###这里输入id,得记住,后面得用到
Email address: ***@qq.com
Comment: 123
You selected this USER-ID:
    "VM_0_178_centos (123) <***@qq.com>"       

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.
输入两次密码确定之后(密码得记住,解密的时候需要用到),就是慢慢的等待吧,可以去玩会儿

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/BFFDD071 2016-11-21
      Key fingerprint = 4A27 CB17 83BF 6938 93E3  C05B 0466 A968 BFFD D071
uid                  VM_0_178_centos (123) <***@qq.com>
sub   2048R/263FFE44 2016-11-21

生成成功
gpg2 -k|K  小写查看所有已导出的公钥
###导出公钥,这里-a 后面接的是id,也就是创建的时候输入的real name
gpg2 --export -a VM_0_178_centos > test.key

###然后把下载把公钥给服务方加密文件就行

加密文件
先把前面的公钥上传,然后倒入此服务器
gpg2 --import test.key

开始加密文件
gpg2 -e -r USERID -o /tmp/xxx $FILE
/tmp/xxx为输出文件的路径;$FILE为需要加密的文件;USERID可通过gpg2 –k来查看。为红框显示部分。

解密
gpg2 –d --batch --passphrase 密码 –o /tmp/xxx $FILE
此处密码为之前生成key时输入的密码;/tmp/xxx为输出文件的路径;$FILE为需要解密的文件;
 

共有 人打赏支持
粉丝 4
博文 90
码字总数 61694
×
空灵飞渡
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: