linux openssh升级8.0

第一步

安装telnet服务端

yum -y install xinetd telnet-server

第二步

默认情况下,系统是不允许root用户telnet远程登录的。如果要使用root用户直接登录,需设置如下内容
注释auth那一行

cat /etc/pam.d/login
#auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

第三步

添加用户登陆设备

cp /etc/securetty /etc/securetty.bak
echo "pts/0" >> /etc/securetty
echo "pts/1" >> /etc/securetty
echo "pts/2" >> /etc/securetty

第四步

开启root用户远程登陆,编辑/etc/pam.d/remote,注释下列这行

vi /etc/pam.d/remote
#auth required pam_securetty.so

第五步

重启telnet和xinetd服务【telnet服务依赖于xinetd服务】

systemctl restart telnet.socket
systemctl restart xinetd

注意

如果开启了防火墙,需要将23端口(系统默认23为telnet端口)添加到防火墙允许的端口的列表中,然后使用telnet协议登录服务器
格式:telnet IP

安全措施做完,下边开始进入openssh升级

第六步

安装依赖包

yum install  -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel pam* zlib*

第七步

下载openssh包和openssl的包

wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz
wget https://ftp.openssl.org/source/old/1.0.2/openssl-1.0.2r.tar.gz

第八步

开始安装openssl
解压文件

tar xf openssl-1.0.2r.tar.gz 

现在系统版本等会升级完毕对比下

[root@host ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
[root@host ~]#

第九步

备份下面2个文件或目录(如果存在的话就执行)

ll /usr/bin/openssl
mv /usr/bin/openssl /usr/bin/openssl_bak
ll /usr/include/openssl
mv /usr/include/openssl /usr/include/openssl_bak

第十步

编译安装新版本的openssl
配置、编译、安装3个命令一起执行
&&符号表示前面的执行成功才会执行后面的

./config shared && make && make install

本人是拆分来做的
每做一步都 echo $? 查看上一条命令执行是否报错 0 表示没有问题

第十一步

下面2个文件或者目录做软链接 (刚才前面的步骤mv备份过原来的)

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
ll /usr/bin/openssl
ll /usr/include/openssl -ld

命令行执行下面2个命令加载新配置

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
/sbin/ldconfig
 查看确认版本。没问题

[root@host openssl-1.0.2r]# openssl version
OpenSSL 1.0.2r 26 Feb 2019

第十二步

安装openssh

[root@host tools]# tar xf openssh-8.0p1.tar.gz 
[root@host tools]# cd openssh-8.0p1
[root@host openssh-8.0p1]# chown -R root.root /data/tools/openssh-8.0p1
[root@host openssh-8.0p1]# pwd
/data/tools/openssh-8.0p1
[root@host openssh-8.0p1]# cd /data/tools/
[root@host openssh-8.0p1]# mkdir ssh-bak
[root@host openssh-8.0p1]# cd ssh-bak
[root@host openssh-8.0p1]# mv /etc/ssh/* ./
[root@host openssh-8.0p1]# cd /data/tools/openssh-8.0p1
[root@host openssh-8.0p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl   --with-zlib   --with-md5-passwords   --with-pam
[root@host openssh-8.0p1]# make && make install

第十三步

开启root登录
修改配置文件最终为如下内容,其他的不要动

[root@host ~]# grep "^PermitRootLogin"  /etc/ssh/sshd_config
PermitRootLogin yes
[root@host ~]# grep  "UseDNS"  /etc/ssh/sshd_config
UseDNS no
[root@host ~]# echo 'PermitRootLogin yes' >>/etc/ssh/sshd_config 

从原先的解压的包中拷贝一些文件到目标位置(如果目标目录存在就覆盖)
(可能下面的ssh.pam文件都没用到,因为sshd_config配置文件貌似没使用它,请自行测试。我这边是拷贝了)

[root@host /data/tools/openssh-8.0p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd
[root@host /data/tools/openssh-8.0p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
[root@host /data/tools/openssh-8.0p1]# chmod +x /etc/init.d/sshd
 
[root@host /data/tools/openssh-8.0p1]# chkconfig --add sshd
[root@host /data/tools/openssh-8.0p1]# systemctl enable sshd

把原先的systemd管理的sshd文件删除或者移走或者删除,不移走的话影响我们重启sshd服务

 mv  /usr/lib/systemd/system/sshd.service  /data/tools/

设置sshd服务开机启动

[root@host ~]# chkconfig sshd on
Note: Forwarding request to 'systemctl enable sshd.socket'.
Created symlink from /etc/systemd/system/sockets.target.wants/sshd.socket to /usr/lib/systemd/system/sshd.socket.

使用systemd方式也行

systemctl stop sshd
systemctl start sshd
systemctl restart sshd

第十四步

测试版本。都正常

ssh -V
OpenSSH_8.0p1, OpenSSL 1.0.2r  26 Feb 2019

如果不是生产机器。可以试着重启机器测试下登录sshd是否正常。我这边测试都没问题
测试没问题后可以把telnet服务关闭了

systemctl disable xinetd.service
systemctl stop telnet.socket
systemctl stop xinetd

第十五步:回滚

如果之前是rpm包安装的。并且按照以上步骤操作,可以直接以下命令进行回滚

yum -y install openssh-clients
yum -y install openssh-server
yum -y install openssh
systemctl restart sshd

可以查看版本是否回滚

¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
有问题评论区回复,或者私信
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥


版权声明:本文为weixin_42434700原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。