创建私有CA及dropbear的编译安装

使用openssl创建私有CA

配置文件/etc/pki/tls/openssl.cnf

certs           = $dir/certs            # Where the issued certs are kept  已经证书存放目录

crl_dir         = $dir/crl              # Where the issued crl are kept  吊销证书列表存放目录

database        = $dir/index.txt        # database index file.  颁发过证书的索引(数据文件)

#unique_subject = no                    # Set to 'no' to allow creation of

                                        # several ctificates with same subject.

new_certs_dir   = $dir/newcerts         # default place for new certs.   创建新证书存放目录

 

certificate     = $dir/cacert.pem       # The CA certificate  CA的自签证书

serial          = $dir/serial           # The current serial number  当前证书的编号

crlnumber       = $dir/crlnumber        # the current crl number   吊销证书编号

                                        # must be commented out to leave a V1 CRL

crl             = $dir/crl.pem          # The current CRL  当前吊销的证书

private_key     = $dir/private/cakey.pem# The private key    CA的私钥

RANDFILE        = $dir/private/.rand    # private random number file

default_days    = 365                           # how long to certify for   默认证书有效期一年

default_crl_days= 30                          # how long before next CRL   默认crl有效期为30

default_md      = sha256           # use SHA-256 by default     使用sha256算法

服务器端:

1、  生成秘钥对

(umask 077 ;openssl genrsa –out private/cakey.pem 2048)

将生成的秘钥权限设置为600的权限,仅属主能访问,并且生成2048位的秘钥

如果想查看公钥可以使用如下指令

openssl rsa -key private/cakey.pem -pubout -out key

1.jpg

2、  生成自签证书

opensl req -new –x509 -key private/cakey.pem -out cacert.pem -days 3655

生成自签证书此时自己就是证书的颁发机构,并且证书的有效期为10年,在生成证书的时候需要填写国家,州或省份,城市,公司名,组织名等等信息,这里默认要求国家省份和组织名要求和CA的一样,如果有用户请求前三项不一样时,可以修改openssl.cnf配置文件将下面的前三项修改optional值即可,这时就不需要要求一致了

[ policy_match ]

countryName             = match

stateOrProvinceName      = match

organizationName    = match

organizationalUnitName  = optional

commonName           = supplied

emailAddress             = optional

    2.jpg

    3、在完成自签证书之后需要创建存放证书数据文件、证书编号文件和证书吊销列表文件,并给出serial的值为01

touch index.txt  serial  crlnumber

echo 01 > serial

 

客户端

假如我这里为httpd服务颁发证书,这时候需要在主机上生成秘钥,保存至应用此证书的服务的配置文件目录下,比如我将证书放在/etc/httpd/ssl

mkdir  /etc/httpd/ssl

cd /etc/httpd/ssl

(umask 077; openssl genrsa -out httpd.key 1024)  生成秘钥

openssl req -new -key httpd.key -out httpd.csr 生成证书签署请求

    3.jpg

    4.jpg


将文件发往CA服务

scp httpd.csr  root@10.1.252.100:/root

 

 

CA服务器签署证书

openssl  ca  -in /root/httpd.csr  -out httpd.crt -days 365

    5.jpg

 

查看生成的证书

openssl x509 -in  httpd.crt -pubout -text|subject|serial|date

6.jpg

将生成好的证书发往客户端

scp httpd.crt root@10.1.252.101:/etc/httpd/ssl

 

 

吊销证书

如果此时证书不想用了,或者被别人给盗用了,这时候需要吊销证书

openssl ca -revoke /etc/pki/CA/newcerts/01.pem

生成吊销证书的编号(第一次吊销一个证书时才需要执行)

echo 01> /etc/pki/CA/crlnumber

更新证书吊销列表

openssl ca -gencrl -out /etc/pki/CA/crl/ca.crl

查看crl文件

openssl crl -in /etc/pki/CA/crl/ca.crl -noout -text

 

 

编译安装dropbear

1、  准备编译安装环境

yum -y groupinstall  “Development Tools”

2、  到官网下载源码包

https://matt.ucc.asn.au/dropbear/dropbear.html

3、  解压源码包

tar xf dropbear-2013.58 

cd dropbear-2013.58

 

4、  开始编译安装,还是老三步(./configure  make  make install

通过查看INSTALL编译安装步骤来进行编译安装

./configure   生成makefile文件

make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"  这里编译安装的工具是可选的,可以根据需求进行取舍,我这里全部都装上

make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"   install   将生成的文件复制到指定的目录下第一个是服务端工具,其他都是客户端工具

7.jpg

 

5、  生成秘钥,利用编译生成的工具dropbearkey工具来生成秘钥

dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key

dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key

8.jpg

6、  启动服务,在我们系统当中默认的ssh服务使用了22端口,所以在启动时使用其他的端口进行启动dropbear服务

dropbear -p 22033  -F    在前台运行 

使用ss –tan 查看22022端口是否已经监听

 

 

7、  测试利用客户端工具dbclient进行访问本地回环地址

dbclient –p 22022 root@127.0.0.1

9.jpg

 

 

最后提供一个服务脚本,就可以用service命令来管理了,脚本内容如下

#!/bin/bash

#

#description: dropbear ssh daemon

#chkconfig: 2345 66 33

#

dsskey=/etc/dropbear/dropbear_dss_host_key

rsakey=/etc/dropbear/dropbear_rsa_host_key

pidfile=/var/run/dropbear.pid

lockfile=/var/lock/subsys/dropbear

dropbear=/usr/local/sbin/dropbear

dropbearkey=/usr/local/bin/dropbearkey

 

[ -r    /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions

[ -r /etc/sysconfig/dropbear ] && . /etc/sysconfig/dropbear

 

key

size=${keysize:-1024}

port=${prot:-22022}

gendsskey() {

           [  -d /etc/dropbear]||mkdir /etc/dropbear

echo -n "Starting genrate the dss key:"

                   $dropbearkey -t dss -f $dsskey

         RETVAL=$?

                    echo

if [ $RETVAL -eq 0 ];then

                    success

                             echo

                    return 0

else

           failure

                    return 1

fi

}

genrsakey() {

           [ ! -d /etc/dropbear]||mkdir /etc/dropbear

           echo -n "Starting genrate the dss key:"

                   $dropbearkey -t rsa -s $keysize  -f $rsakey

           RETVAL=$?

                    echo       

if [ $RETVAL -eq 0 ];then

                    success

                    echo

                    return 0

else

           failure

                             echo

                    return 1

fi

}        

start()  {

[ -e $dsskey ] ||gendsskey

           [ -e $rsakey ] || genrsakey

if

[  -e  $lockfile  ] ;then

           echo -n "dropbear daemon is already running."

                    success

           echo

                    exit 0

fi

 

echo -n "starting dropbear: "

           daemon   –pidfile="$pidfile" 

$dropbear -p $port -d $dsskey -r $rsakey

                             RETVAL=$?

                    echo

if [ $RETVAL -eq 0 ];then

                    touch $lockfile

                    return 0

           else

                    rm -rf $lockfile $pidfile

           return 1

fi

}

stop() {

if  [  !  -e $lockfile ] ;then

           echo -n "dropbear service is stoped"

success

echo

           exit 1

fi

           echo -n "stopping dropbear daemon:"

           killproc dropbear

           RETVAL=$?

           echo

if [ $RETVAL -eq 0 ] ;then

           rm -rf $lockfile $pidfile

           return 0

else

           return 1

fi

 

}

status() {

if [ -e $lockfile ] ;then

echo "dropbear is running "

else

echo "dropbear is stoped.."

fi

}

usage() {

echo "Usage:dropbear {start|stop|restart|status|genrsakey|gendsskey}"

}

case $1 in

start)

start ;;

stop)

stop

;;

restart)

stop

start

 ;;

status)

status

 ;;

 

genrsakey)

genrsakey

 ;;

gendsskey)

gendsskey

 ;;

*)

usage

 ;;

esac

 

将此脚本复制到/etc/init.d      目录下,并给文件添加执行权限

chkconfig –add dropbear  dropbear加到服务列表中去,此时就可以使用service命令来管理服务了

 

 

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

(0)
fszxxxksfszxxxks
上一篇 2016-09-26
下一篇 2016-09-26

相关推荐

  • 初探SElinux

    SELinux介绍: SELinux: Secure Enhanced Linux(安全强化的linux),是美国国家安全局(NSA=The National Security Agency)和 SCC(Secure Computing Corporation)开发的Linux的一个强制访问控制的安全模块。2000年以GNU GPL发布,Linux内核2.6…

    Linux干货 2016-10-09
  • 使用Openssl构建私有CA

    使用Openssl构建私有CA Openssl是SSL的开源实现,是一种安全机密程序,主要用于提高远程登录访问的安全性。也是目前加密算法所使用的工具之一,功能很强大。     Openssl为网络通信提供安全及数据完整性的一种安全协议,包括了主要的密码算法、常用的密钥和证书封装管理功能(CA)以及SSL协议,并提供了丰…

    Linux干货 2015-10-07
  • Linux入门之计算机组成及其功能

    计算机基础以及Linux基础

    2018-03-06
  • CentOS6.7上编译安装php

    环境:CentOS6.7,minimal安装。 前提条件:安装了编译环境,安装了Apache/Nginx,安装了MySQL/MariaDB。具体安装见:http://www.178linux.com/16583    http://www.178linux.com/17497  1、解决依赖关系: 请配置好yum源(系统安装源及…

    Linux干货 2016-06-03
  • VSFTPD+PAM+[基于文件虚拟用户认证 | 基于MYSQL虚拟用户认证]

    VSFTPD+PAM+[基于文件虚拟用户认证 | 基于MYSQL虚拟用户认证] VSFTPD+PAM+[基于文件虚拟用户认证 | 基于MYSQL虚拟用户认证] 一、实验环境 二、实验步骤 1、通过mysql数据库方式虚拟用户认证 1.1数据库配置 1.2FTP配置 1.3测试 2、通过文件方式进行虚拟用户认证 一、实验环境 CentOS 6.7+vsftpd…

    Linux干货 2016-04-18
  • nginx_http_proxy,upstream,stream模块简析

    一. ngx_http_proxy_module模块:         模块功能: 为后端httpd服务做反向代理, 并且与Httpd 之间使用http进行通信       1、proxy_pass URL;  &nbs…

    Linux干货 2016-10-29

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-26 13:29

    文章实操性很强,每一步都很明确,整个实验过程很流畅,赞一个。