CentOS系统升级OpenSSH版本

摘要:
core-4.0-noarch:graphics-4.0-noarch:printing-4.0-noarkDistributorID:

一 、CentOS 6.x 升级 OpenSSH

1、查看环境:

[root@localhost ~]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:    CentOS
Description:    CentOS release 6.6 (Final)
Release:    6.6
Codename:    Final
[root@localhost ~]# ssh -V
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
[root@localhost ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013

2、备份ssh目录(重要)并安装telnet(避免ssh升级出现问题,导致无法远程管理)

[root@localhost ~]# cp -rf /etc/ssh /etc/ssh.bak

  安装并配置telnet

[root@localhost ~]# yum -y install telnet telnet-server
[root@localhost ~]# vi /etc/xinetd.d/telnet

# default: on
# description: The telnet server serves telnet sessions; it uses 
#    unencrypted username/password pairs for authentication.
service telnet
{
    flags        = REUSE
    socket_type    = stream        
    wait        = no
    user        = root
    server        = /usr/sbin/in.telnetd
    log_on_failure    += USERID
    disable        = yes
}

  默认不允许root用户的登陆,将disable=yes 修改为 no

[root@localhost ~]# vi /etc/securetty
// 增加以下内容,如果登录用户较多,需要更多的pts/*
pts/0
pts/1
pts/2

  配置完成后启动telnet服务

[root@localhost ~]# service xinetd start
[root@localhost ~]# service xinetd status
xinetd (pid  28430) is running...

  注:ssh升级后建议再修改,还原设置

3、OpenSSH安装

  3.1 安装依赖包

[root@localhost ~]# yum install -y gcc openssl-devel pam-devel rpm-build

  3.2 下载安装包

[root@localhost Downloads]# wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.8p1.tar.gz

  3.3 解压并编译安装

[root@localhost Downloads]# tar -zxvf openssh-7.8p1.tar.gz 
[root@localhost Downloads]# cd openssh-7.8p1
[root@localhost openssh-7.8p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers
[root@localhost openssh-7.8p1]# make && make install

  3.4 配置OpenSSH

[root@localhost openssh-7.8p1]# vi /etc/ssh/sshd_config
// 将 #PermitRootLogin yes   修改为   PermitRootLogin yes
// 或者执行如下命令
[root@localhost openssh-7.8p1]# sed -i '/^#PermitRootLogin/s/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config

  3.5 重启sshd服务

[root@localhost openssh-7.8p1]# service sshd restart 
[root@localhost openssh-7.8p1]# service sshd status
openssh-daemon (pid  28331) is running...
[root@localhost openssh-7.8p1]# ssh -V
OpenSSH_7.8p1, OpenSSL 1.0.1e-fips 11 Feb 2013

二、CentOS 7.x 升级 OpenSSH

1、查看环境:

[root@localhost ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:    CentOS
Description:    CentOS Linux release 7.2.1511 (Core) 
Release:    7.2.1511
Codename:    Core
[root@localhost ~]# ssh -V
OpenSSH_6.6.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013
[root@localhost ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

2、同上,备份ssh目录(重要)并安装telnet(避免ssh升级出现问题,导致无法远程管理)

[root@localhost ~]# cp -rf /etc/ssh /etc/ssh.bak

  安装并配置telnet

[root@localhost ~]# yum -y install telnet telnet-server xinetd
[root@localhost ~]# vi /etc/xinetd.d/telnet

    #default:yes
    ## description: The telnet server servestelnet sessions; it uses
    ## unencrypted username/password pairs for authentication.
    service telnet
    {
      flags = REUSE
      socket_type = stream
      wait = no
      user = root
      server =/usr/sbin/in.telnetd
      log_on_failure += USERID
      disable = yes
    }

  默认不允许root用户的登陆,将disable=yes 修改为 no

[root@localhost ~]# vi /etc/securetty
// 增加以下内容,如果登录用户较多,需要更多的pts/*
pts/0
pts/1
pts/2

  配置完成后启动telnet服务

[root@localhost ~]# systemctl start telnet.socket

[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# systemctl status xinetd
● xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-12-17 10:45:35 CST; 23h ago
 Main PID: 4217 (xinetd)
   CGroup: /system.slice/xinetd.service
           └─4217 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid

  注:ssh升级后建议再修改,还原设置

3、OpenSSH安装

  3.1 安装依赖包

[root@localhost ~]# yum install -y gcc openssl-devel pam-devel rpm-build

  3.2 下载安装包

  OpenSSH需要依赖zlib和OpenSSL,因此需要从官网下载三者的源码包。三者源码下载地址:
             http://www.zlib.net/         

             http://www.openssl.org/         

             http://www.openssh.org/

        分别下载openssh-7.6p1.tar.gz、openssl-1.0.2m.tar.gz和zlib-1.2.11.tar.gz

[root@localhost Downloads]# wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.6p1.tar.gz
[root@localhost Downloads]# wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2m.tar.gz 
[root@localhost Downloads]# wget http://www.zlib.net/zlib-1.2.11.tar.gz 
[root@localhost Downloads]# ll 
total 7300 
-rw-r--r--. 1 root root 1548026 Aug 24 07:53 openssh-7.6p1.tar.gz 
-rw-r--r--. 1 root root 5373776 Nov 2 2017 openssl-1.0.2m.tar.gz 
-rw-r--r--. 1 root root 607698 Jan 16 2017 zlib-1.2.11.tar.gz

  3.3 编译并安装配置zlib、openssl

// 编译安装zlib
[root@localhost Downloads]# tar -zxvf zlib-1.2.11.tar.gz 
[root@localhost Downloads]# cd zlib-1.2.11/
[root@localhost zlib-1.2.11]# ./configure --prefix=/usr/local/zlib-1.2.11 -share
[root@localhost zlib-1.2.11]# make && make install
[root@localhost zlib-1.2.11]# vi /etc/ld.so.conf              // 配置库文件搜索路径,在最后加入
/usr/local/zlib-1.2.11/lib
[root@localhost zlib-1.2.11]# ldconfig -v // 刷新缓存文件/etc/ld.so.cache [root@localhost zlib-1.2.11]# ln -s /usr/local/zlib-1.2.11 /usr/local/zlib [root@localhost zlib-1.2.11]# cd /root/Downloads/ // 编译安装openssl [root@localhost Downloads]# tar -zxvf openssl-1.0.2m.tar.gz [root@localhost Downloads]# cd openssl-1.0.2m/ [root@localhost openssl-1.0.2m]# ./config --prefix=/usr/local/openssl-1.0.2m --with-zlib-lib=/usr/local/zlib-1.2.11/lib --with-zlib-include=/usr/local/zlib-1.2.11/include [root@localhost openssl-1.0.2m]# make && make install [root@localhost openssl-1.0.2m]# vi /etc/ld.so.conf // 配置库文件搜索路径,在最后加入
/usr/local/openssl-1.0.2m/lib
[root@localhost openssl-1.0.2m]# ldconfig -v // 刷新缓存文件/etc/ld.so.cache [root@localhost openssl-1.0.2m]# ln -s /usr/local/openssl-1.0.2m /usr/local/openssl [root@localhost openssl-1.0.2m]# vi /etc/profile // 配置环境变量,在最后加入以下两行 PATH=/usr/local/openssl/bin:$PATH export PATH [root@localhost openssl-1.0.2m]# source /etc/profile // 让配置生效 [root@localhost openssl-1.0.2m]# openssl version -a // 查看openssl版本,验证是否安装成功 OpenSSL 1.0.2m 14 Aug 2018
built on: reproducible build, date unspecified
platform: linux-x86_64
options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)
compiler: gcc -I. -I.. -I../include -I/usr/local/zlib-1.2.11/include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/local/openssl-1.0.2m/ssl"

  3.4 卸载原OpenSSH

[root@localhost Downloads]# rpm -qa |grep openssh
openssh-clients-6.6.1p1-22.el7.x86_64
openssh-6.6.1p1-22.el7.x86_64
openssh-server-6.6.1p1-22.el7.x86_64
[root@localhost Downloads]# for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps;done

  3.5 编译安装配置OpenSSH

[root@localhost Downloads]# tar -zxvf openssh-7.6p1.tar.gz 
[root@localhost Downloads]# cd openssh-7.6p1/
[root@localhost openssh-7.6p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam--with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening --with-tcp-wrappers
[root@localhost openssh-7.6p1]# rm -rf /etc/ssh
[root@localhost openssh-7.6p1]# make && make install
[root@localhost openssh-7.6p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-7.6p1]# chkconfig --add sshd
[root@localhost openssh-7.6p1]# chkconfig sshd on
[root@localhost openssh-7.6p1]# chkconfig --list|grep sshd
[root@localhost openssh-7.6p1]# sed -i "32a PermitRootLogin yes" /etc/ssh/sshd_config

  3.6 重启sshd服务

[root@localhost openssh-7.6p1]# systemctl restart sshd
[root@localhost openssh-7.6p1]# systemctl status sshd
● sshd.service - SYSV: OpenSSH server daemon
   Loaded: loaded (/etc/rc.d/init.d/sshd)
   Active: active (running) since Tue 2018-12-18 14:45:59 CST; 11s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 16931 ExecStart=/etc/rc.d/init.d/sshd start (code=exited, status=0/SUCCESS)
 Main PID: 16939 (sshd)
   CGroup: /system.slice/sshd.service
           └─16939 /usr/sbin/sshd

Dec 18 14:45:59 localhost.localdomain systemd[1]: Starting SYSV: OpenSSH server daemon...
Dec 18 14:45:59 localhost.localdomain sshd[16939]: Server listening on 0.0.0.0 port 22.
Dec 18 14:45:59 localhost.localdomain sshd[16939]: Server listening on :: port 22.
Dec 18 14:45:59 localhost.localdomain sshd[16931]: Starting sshd:[  OK  ]
Dec 18 14:45:59 localhost.localdomain systemd[1]: Started SYSV: OpenSSH server daemon.
[root@localhost openssh-7.6p1]# ssh -V
OpenSSH_7.6p1, OpenSSL 1.0.2k-fips 26 Jan 2017

 踩坑:

  以下是linux打开端口命令的使用方法。
  nc -lp 23 &(打开23端口,即telnet)
  netstat -an | grep 23 (查看是否打开23端口)

  使用nmap检测端口是否打开

  nmap X.X.X.X -p 端口号

参考链接:http://bbs.51cto.com/thread-1547903-1.html
参考链接:https://blog.csdn.net/levy_cui/article/details/53100315
参考链接:https://www.cnblogs.com/liangjingfu/p/9635657.html 

免责声明:文章转载自《CentOS系统升级OpenSSH版本》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇mtd-utils交叉编译安装Redhat更新源下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

如何测试本地是否能够正常访问云服务器的 Web 端口

在windows环境下打开DOS命令行 使用telnet命令。例如 telnet www.baidu.com 80 插播一条小知识:DOS下清屏的命令是cls。 首先很不幸,出现了【'telnet' 不是内部或外部命令,也不是可运行的程序 或批处理文件。】这个错误。 这是因为Win7默认没有安装telnet功能,所以你直接用telnet命令是用不了的。你...

关于Docker目录挂载的总结(一)

Docker容器启动的时候,如果要挂载宿主机的一个目录,可以用-v参数指定。 譬如我要启动一个centos容器,宿主机的/test目录挂载到容器的/soft目录,可通过以下方式指定: # docker run -it -v /test:/soft centos /bin/bash 这样在容器启动后,容器内会自动创建/soft的目录。通过这种方式,我们可以明...

SLB(Server Load Balancing 服务器负载均衡)

简介SLB(Server Load Balancing 服务器负载均衡)用于实现多个服务器之间的负载均衡。SLB虚拟出一个服务器,对用户呈现的就是这个虚拟的服务器。虚拟服务器代表的是多个真实服务器的群集,当客户端向虚拟服务器发起连接时,SLB通过某种均衡算法,转发到某真实服务器。负载均衡的2种算法:WRR(weighted round robin 加权循环...

sklearn调用SVM算法

1、支撑向量机SVM是一种非常重要和广泛的机器学习算法,它的算法出发点是尽可能找到最优的决策边界,使得模型的泛化能力尽可能地好,因此SVM对未来数据的预测也是更加准确的。 2、SVM既可以解决分类问题,又可以解决回归问题,原理整体相似,不过也稍有不同。 在sklearn章调用SVM算法的代码实现如下所示: #(一)sklearn中利用SVM算法解决分类...

诡异的socket连接失败

最近在搞ELK日志平台,部署filebeat收集日志时(输出到redis),出现了经典的【连接被目标机器积极拒绝】异常, 1)环境配置:   开发机,开发服务机(开发机上的virtualbox虚拟机,启动了ELK服务)、测试机、测试服务机(ELK) 2)本机(开发机)使用可输出日志到开发服务机 + 测试服务机 3)测试机可输出日志到开发服务机,配置为测试服...

DGL学习(三): 消息传递教程

在本节中,我们将不同级别的消息传递API与PageRank一起使用。 在DGL中,消息传递和功能转换是用户定义的函数(UDF)。 PageRank 算法: 在PageRank的每次迭代中,每个节点(网页)首先将其PageRank值均匀地分散到其下游节点。 每个节点的新PageRank值是通过汇总从其邻居收到的PageRank值来计算的,然后通过阻尼因子(d...