openssl1.0.2n_openssh7.5sp1整合外加nginx ssl升级教程

一、准备工作
上来先查一下iptables的状态和selinux的状态
先检查一下xinetd之前有没有
service xinetd status
[root@master ~]# chkconfig --list |grep iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@master ~]# chkconfig iptables off
[root@master ~]# chkconfig --list |grep iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@master ~]# service iptables status
[root@master ~]# service iptables stop
[root@master ~]# vim /etc/selinux/config
7 SELINUX=disabled
[root@master ~]# setenforce 0


二、安装telnet服务
1.安装软件
# yum install gcc pam-devel zlib-devel telnet-server* telnet

2.启用telnet服务
# vi /etc/xinetd.d/telnet
将其中disable字段的yes改为no以启用telnet服务
在结尾增加
# vi /etc/securetty
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
在此时使用终端用telnet连接上主机!!!!!!!
# cp -rp /etc/securetty /etc/securetty.old #允许root用户通过telnet登录
# service xinetd start #启动telnet服务
# chkconfig xinetd on #使telnet服务开机启动,避免升级过程中服务器意外重启后无法远程登录系统
#chkconfig --list | grep xinetd
xinetd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@master yum.repos.d]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
3.测试telnet能否正常登入系统
这时连接上telnet以防后续步骤出现问题
telnet出现问题连接不上需要做以下操作

这时开启另外一个标签使用telnet 连接23号端口
CentOS release 6.8 (Final)
Kernel 2.6.32-642.el6.x86_64 on an x86_64

login: root
Password:
Last login: Tue Apr 24 10:53:15 from 192.168.37.1
[root@master ~]#
[root@master ~]#
确保能够登录成功并且不要关闭这个telnet窗口留着当备用


三、升级OpenSSL

注:openssh7.5p1依赖的openssl的版本为>1.0.1e 并且 < 1.1.0。我们当前安装的是1.0.2n

wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2n.tar.gz
tar -zxvf openssl-1.0.2n.tar.gz
cd openssl-1.0.2n
./config shared zlib
#一定要加上shared 参数,要不在安装openssh的时候就无法找到
make depend
make && make install
备份原来的openssl
> mv /usr/bin/openssl /usr/bin/openssl.bak
> mv /usr/include/openssl /usr/include/openssl.bak
因为源码安装默认安装的位置是 /usr/local/ssl 需要将创建软链接到系统位置
> ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
> ln -s /usr/local/ssl/include/openssl /usr/include/openssl
将openssl 的lib 库添加到系统
> echo "/usr/local/ssl/lib/" >> /etc/ld.so.conf
> ldconfig #使新添加的lib 被系统找到
查看openssl版本
> openssl version -a

至此opensll 已经成功升级到1.0.2n

三、升级OpenSSH
1.备份当前openssh
mv /etc/ssh /etc/ssh.old
mv /etc/init.d/sshd /etc/init.d/sshd.old

2.卸载当前openssh
#rpm -qa | grep openssh
openssh-askpass-5.3p1-117.el6.x86_64
openssh-5.3p1-117.el6.x86_64
openssh-clients-5.3p1-117.el6.x86_64
openssh-server-5.3p1-117.el6.x86_64
#这里一定要按顺序卸载否则可能会出现依赖报错 如果版本不同找到对应的卸载就可以了
# rpm -e --nodeps openssh-5.3p1-117.el6.x86_64
# rpm -e --nodeps openssh-server-5.3p1-117.el6.x86_64

注意:卸载过程中如果出现以下错误
!!!#####error reading information on service sshd: No such file or directory
error: %preun(openssh-server-5.3p1-117.el6.x86_64) scriptlet failed, exit status 1 报这个错就用下面这条命令

# rpm -e --noscripts openssh-server-5.3p1-117.el6.x86_64

# rpm -e --nodeps openssh-clients-5.3p1-117.el6.x86_64
# rpm -e --nodeps openssh-askpass-5.3p1-117.el6.x86_64
# rpm -qa | grep openssh


3.openssh安装前环境配置
# install -v -m700 -d /var/lib/sshd
# chown -v root:sys /var/lib/sshd
当前系统sshd用户已经存在的话以下不用操作
# groupadd -g 50 sshd
# useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd

4.解压openssh_7.5p1源码并编译安装
# cd ..
# wget https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz
# tar -zxvf openssh-7.5p1.tar.gz
# cd openssh-7.5p1

checking OpenSSL header version... not found configure: error: OpenSSL version header not found.问题

系统没有找到openssl库,需要运行ldconfig。

#############################test
ldconfig

./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-openssl-includes=/usr --with-ssl-dir=/usr/local/ssl --with-privsep-path=/var/lib/sshd
#需要指定openssl的安装路径

#############################


######
PAM is enabled. You may need to install a PAM control file
for sshd, otherwise password authentication may fail.
Example PAM control files can be found in the contrib/
subdirectory
这里不用管

# make
# make install
make && make install

######
返回这些信息
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
返回这些信息


5.openssh安装后环境配置
# 在openssh编译目录执行如下命令
# install -v -m755 contrib/ssh-copy-id /usr/bin
# install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
# install -v -m755 -d /usr/share/doc/openssh-7.5p1
# install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.5p1
# ssh -V #验证是否升级成功

6.启用OpenSSH服务
# 在openssh编译目录执行如下目录
# echo 'X11Forwarding yes' >> /etc/ssh/sshd_config
# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config #允许root用户通过ssh登录
# cp -p contrib/redhat/sshd.init /etc/init.d/sshd
# chmod +x /etc/init.d/sshd
# chkconfig --add sshd
# chkconfig sshd on
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

7.恢复原来的配置信息
# cp -rp /etc/securetty /etc/securetty.new
# cp -rp /etc/securetty.old /etc/securetty
如需还原之前的ssh配置信息,可直接删除升级后的配置信息,恢复备份。
# cp -rp /etc/ssh /etc/ssh.new
# rm -rf /etc/ssh
# cp -rp /etc/ssh.old /etc/ssh

# vim /etc/ssh/ssh_config
50 #GSSAPIAuthentication yes #注释掉这一行
确保安全可以/GSS搜索注释所有带GSS的

# vim /etc/ssh/sshd_config
# 97 UsePAM no #去掉注释然后把参数改为no
##注释掉下面三个参数
81 #GSSAPIAuthentication yes
83 #GSSAPICleanupCredentials yes
确保安全可以/GSS搜索注释所有带GSS的
42 PermitRootLogin yes 这个去掉注释启用并改成yes

####需要考虑到防火墙重启会挡住端口要关闭防火墙相关的东西
重启一下sshd试试
# service sshd restart


!!!!!!!!!这里重启系统
[root@master ~]# reboot

这里重新连接服务器
一个ssh的连接 #注意端口号还是以前
一个telnet的连接 端口号是23


到这里就结束了
然后进行以下善后
# vi /etc/xinetd.d/telnet
将其中disable字段的改为yes关闭telnet功能
service xinetd stop
chkconfig xinetd off
在结尾中删除以下内容
# vi /etc/securetty
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8


以前如果是开启防火墙的把防火墙开启
chkconfig iptables on
service iptables start

 

以下内容是openssl升级后nginx升级openssl 的详细过程

后来 你发现nginx一直都运行在旧版本 使用./nginx -V查看时会显示如下信息
nginx version: openresty/1.11.2.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013 (running with OpenSSL 1.0.2n 7 Dec 2017)
编译版本和运行时版本不统一 原因在于nginx有两个openssl的动态依赖库文件
我们使用ldd命令查看一下
#ldd nginx

linux-vdso.so.1 => (0x00007ffcd05d6000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb445573000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb445356000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fb44511f000)
libluajit-5.1.so.2 => /usr/local/openresty/luajit/lib/libluajit-5.1.so.2 (0x00007fb444ea7000)
libm.so.6 => /lib64/libm.so.6 (0x00007fb444c23000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x00007fb4449f6000)
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fb444786000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fb44434d000)
libz.so.1 => /lib64/libz.so.1 (0x00007fb444137000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb443da3000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb445777000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fb443ba0000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb44398a000)


其中这两个是依赖的openssl的动态库文件
libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fb444786000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fb44434d000)

查看一下怎么个依赖关系你会发现
[root@es ~]# ll /usr/lib64/libssl*
-rwxr-xr-x. 1 root root 311768 Mar 23 2017 /usr/lib64/libssl3.so
lrwxrwxrwx. 1 root root 16 Mar 20 08:57 /usr/lib64/libssl.so -> libssl.so.1.0.1e
lrwxrwxrwx. 1 root root 16 Mar 12 11:43 /usr/lib64/libssl.so.10 -> libssl.so.1.0.1e
-rwxr-xr-x. 1 root root 443416 Mar 23 2017 /usr/lib64/libssl.so.1.0.1e

libssl.so 和 libssl.so.10 最终依赖的都是libssl.so.1.0.1e

然后再看libcrypto的
[root@es ~]# ll /usr/lib64/libcrypto*
lrwxrwxrwx. 1 root root 19 Mar 20 08:57 /usr/lib64/libcrypto.so -> libcrypto.so.1.0.1e
lrwxrwxrwx. 1 root root 19 Mar 12 11:43 /usr/lib64/libcrypto.so.10 -> libcrypto.so.1.0.1e
-rwxr-xr-x. 1 root root 1971488 Mar 23 2017 /usr/lib64/libcrypto.so.1.0.1e

libcrypto.so 和 libcrypto.so.10 最终依赖的都是libcrypto.so.1.0.1e

综上所述备份替换库文件
# cp /usr/lib64/libssl.so.1.0.1e /usr/lib64/libssl.so.1.0.1e.bak
# cp /usr/lib64/libcrypto.so.1.0.1e /usr/lib64/libcrypto.so.1.0.1e.bak

然后把直接安装好的/usr/local/ssl/lib/路径下面的库文件以软连接的形式弄过来
# rm -rf /usr/lib64/libssl.so.1.0.1e
# rm -rf /usr/lib64/libcrypto.so.1.0.1e

# ln -s /usr/local/ssl/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.1e
# ln -s /usr/local/ssl/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.1e

换完库文件重新编译以前的nginx替换过来就行了
# cd /usr/local/software/openresty_auto_install/openresty-1.11.2.2
#
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
不推荐! 以下这种方式有可能会make不成功 如果不成功请用下面的方式 谨慎使用
./configure --prefix=/usr/local/openresty --with-http_stub_status_module --with-http_gzip_static_module --with-luajit
# make
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#指定openssl源码的位置,一定要跟之前安装openssl用相同的源码包
./configure --prefix=/usr/local/openresty --with-http_stub_status_module --with-http_gzip_static_module --with-luajit --with-openssl=/usr/local/software/openssl-1.0.2n
# make

# /usr/local/software/openresty_auto_install/openresty-1.11.2.2/build/nginx-1.11.2/objs/nginx
把这个文件替换原来nginx的启动文件
先备份
# cp -rp /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/nginx/sbin/nginx.bakssl101e
# cp -rp /usr/local/software/openresty_auto_install/openresty-1.11.2.2/build/nginx-1.11.2/objs/nginx /usr/local/openresty/nginx/sbin/nginx.bakssl102n
# cp -rp /usr/local/software/openresty_auto_install/openresty-1.11.2.2/build/nginx-1.11.2/objs/nginx /usr/local/openresty/nginx/sbin/nginx

# /usr/local/openresty/nginx/sbin/nginx -V


[root@kp sbin]# /usr/local/openresty/nginx/sbin/nginx -V

显示以下信息那么久成功了
nginx version: openresty/1.11.2.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.2n 7 Dec 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.7 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-http_stub_status_module --with-http_gzip_static_module --with-openssl=/usr/local/software/openssl-1.0.2n --with-http_ssl_module

 

转载于:https://www.cnblogs.com/n64wnc/p/8984009.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值