最近客户处有一些linux操做系统安装了较旧的SSH,存在版本漏洞,小研究了一下,安装最新版本的OPENSSH,能够平滑升级。linux
ssh登陆到要安装的服务器上,查看当前版本
[root@localhost ~]# ssh -V
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
在/目录下建立/tools目录,经过FTP工具上传安装文件到该目录下(文件能够到官网去下载)
mkdir /tools
[root@localhost tools]# ls -ltrh
total 9.2M
-rw-r--r--. 1 root root 1.5M Jun 28 09:14 openssh-7.2p2.tar.gz
-rw-r--r--. 1 root root 5.1M Jun 28 09:14 openssl-1.0.2h.tar.gz
-rw-r--r--. 1 root root 2.7M Jun 28 09:14 zlib-1.2.8.tar.gz
-----------------------------------------配置YUM---------------------------------------------------------centos
插入系统安装光盘,配置yum源。(也能够上传ISO到服务器,而后mount –o loop <ISO文件路径> /mnt)
[root@localhost ~]# mount /dev/cdrom1 /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# touch local.repo
[root@localhost yum.repos.d]# vi local.repo
[root@localhost yum.repos.d]# cat local.repo
[local]
name=centos
gpgcheck=0
enable=1
baseurl=file:///mnt
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
local | 4.0 kB 00:00 ...
local/group_gz | 220 kB 00:00 ...
local/filelists_db | 5.8 MB 00:00 ...
local/primary_db | 4.4 MB 00:00 ...
local/other_db | 2.7 MB 00:00 ...
Metadata Cache Created
-------------------升级前先安装好TELNET服务器,以防止SSH重启没法登陆------------------
使用yum安装Telnet服务
yum install telnet-server服务器
修改/etc/xinetd.dtelnet文件disable=no(原有值为yes)
sed -i '12 s/yes/no/' /etc/xinetd.d/telnetssh
配置容许root用户远程登陆,而后重启服务
[root@localhost xinetd.d]# echo 'pts/0' >>/etc/securetty
[root@localhost xinetd.d]# echo 'pts/1' >>/etc/securetty
[root@localhost xinetd.d]# service xinetd restart
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]
-----------------------使用telnet登陆系统--------------------------------------------------ide
用ROOT帐户使用telnet登陆系统执行修改OPENSSH操做工具
-----------------------使用yum移除openssh--------------------------------------------------oop
yum remove openssh<会删除较多依赖包>ui
或者url
rpm -e openssh-server-5.3p1-94.el6.x86_64idea
rpm -e openssh-askpass-5.3p1-94.el6.x86_64
------------------------安装zlib-----------------------------------------------------------
cd /tools
tar -xvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib && make && make install
-------------------------安装openssl-------------------------------------------------------
tar -xvf openssl-1.0.2h.tar.gz
cd openssl-1.0.2h
./config --prefix=/usr/local/openssl
make depend
make
make install
-----------------------安装openssh-----------------------------------------------------------------------------
tar -xvf openssh-7.2p2.tar.gz
cd openssh-7.2p2
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-md5-passwords --without-hardening && make && make install
-------------------------拷贝SSHD服务文件--------------------------------------------------
cp contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
--------------------------修改SSHD服务文件-------------------------------------------------
修改SSHD文件
vi /etc/init.d/sshd
修改如下内容
SSHD=/usr/sbin/sshd 为 SSHD=/usr/local/openssh/sbin/sshd
/usr/bin/ssh-keygen -A 为 /usr/local/openssh/bin/ssh-keygen -A
保存退出
加入到系统服务
[root@localhost openssh-7.2p2]# chkconfig --add sshd
查看系统启动服务是否增长改项
[root@localhost openssh-7.2p2]# chkconfig --list |grep sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
---------------------------替换SSH及SSL命令------------------------------------------------
mv /usr/bin/ssh /usr/bin/ssh.old
ln -s /usr/local/openssh/bin/ssh /usr/bin/ssh
mv /usr/bin/openssl /usr/bin/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost ~]# ssh -V
OpenSSH_7.2p2, OpenSSL 1.0.2h 3 May 2016
[root@localhost ~]# openssl version -a
OpenSSL 1.0.2h 3 May 2016
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 -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 -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/ssl"
升级到新版本后,默认不容许root用户远程登陆
cat /etc/ssh/sshd_config
修改
PermitRootLogin yes
从新启动SSHD服务。
service sshd start
完成手动升级