2022-01-07-centos7.6升级ssl和ssh

下载软件

http://www.zlib.net/zlib-1.2.11.tar.gz

https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.8p1.tar.gz

openssl-1.1.1l.tar.gz

脚本

#!/bin/bash

path_src=`pwd`

cd $path_src

tar -xvf openssl-1.1.1l.tar.gz

tar -xvf openssh-8.8p1.tar.gz

tar -xvf zlib-1.2.11.tar.gz

tar -xvf gcc_package.tar.gz

#0.检查依赖

rpm -q gcc

if [ $? != 0]; then

  yum localinstall gcc_package -y

fi

#1.zlib

cd zlib-1.2.11

./configure --prefix=/usr/local/zlib

make && make install

cd ..

#2.编译安装openssl

cd openssl-1.1.1l

./config --prefix=/usr/local/ssl -d shared

make && make install

cd ..

#3.安装openssh

cd openssh-8.8p1

./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl

make && make install

cd ..

#4.sshd_config 文件修改

echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config

echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config

echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config

#5.替换/etc/ssh里的文件

mv /usr/sbin/sshd /usr/sbin/sshd.bak

cp  /usr/local/openssh/sbin/sshd /usr/sbin/sshd

mv /usr/bin/ssh /usr/bin/ssh.bak

cp  /usr/local/openssh/bin/ssh /usr/bin/ssh

mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak

cp  /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

mv /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak

cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub

mv /etc/ssh/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key.pub.bak

cp /usr/local/openssh/etc/ssh_host_dsa_key.pub /etc/ssh/ssh_host_dsa_key.pub

#6.更换openssl文件 这一步操作完成后 输入openssl version会发现openssl版本已经发生变化

mv /usr/bin/openssl /usr/bin/openssl_bak

cp /usr/local/ssl/bin/openssl /usr/bin/openssl

mv /usr/include/openssl /usr/include/openssl_bak

ln -s /usr/local/ssl/include/openssl /usr/include/openssl

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf

/sbin/ldconfig

cd ..

#7.替换启动文件

cd openssh-8.8p1

cp -a contrib/redhat/sshd.init /etc/init.d/sshd

cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

chmod +x /etc/init.d/sshd

chkconfig --add  sshd

systemctl enable sshd

#8.sshd.service 会跟etc/init.d/sshd 文件形成冲突,而sshd.socket重启之后会发生报错所以进行移除

mv  /usr/lib/systemd/system/sshd.service  /usr/lib/systemd/system/sshd.service_bak

mv  /usr/lib/systemd/system/sshd.socket  /usr/lib/systemd/system/sshd.socket_bak

#9.添加ssh开机启动

chkconfig sshd on

/etc/init.d/sshd restart

#10.重新生成rsa dsa key (这一步是因为怕本地证书不符,所以加上的,可以不进行操作,请自测)

ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -P "" -q

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -P "" -q

#11.ssh  -V  进行测试

ssh -V

openssl version

你可能感兴趣的:(2022-01-07-centos7.6升级ssl和ssh)