一、準備工作
[root@localhost ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cp /etc/yum.repos.d/rhel-source.repo /etc/yum.repos.d/yum.repo
[root@localhost ~]# vi /etc/yum.repos.d/yum.repo
[a]
name=a
baseurl=file:///media
enabled=1
gpgcheck=0
[root@localhost ~]# yum install gcc pam-devel telnet telnet-server xinetd
[root@localhost ~]# mkdir /soft
[root@localhost ~]# cd /soft/
[root@localhost soft]# ls
openssl-1.0.2o.tar.gz zlib-1.2.11.tar.gz openssh-7.7p1.tar.gz
[root@localhost soft]# vi /etc/xinetd.d/telnet
修改disible = no
[root@localhost soft]# mv /etc/securetty /etc/securetty.old
[root@localhost soft]# service xinetd restart
停止 xinetd: [失敗]
正在啓動 xinetd: [確定]
[root@localhost soft]# telnet IP 23
以下是關閉防火牆的步奏,suse和redhat、centos略有不同:
1、centos、redhat關閉防火牆步奏:
[root@localhost soft]# iptables -F
[root@localhost soft]# iptables -X
[root@localhost soft]# service iptables stop
iptables:將鏈設置爲政策 ACCEPT:filter [確定]
iptables:清除防火牆規則: [確定]
iptables:正在卸載模塊: [確定]
[root@localhost soft]# chkconfig iptables off
2、suse關閉防火牆步奏:
因爲系統重啓防火牆會自動開啓,導致ssh遠程無法登陸,所以需要永久性關閉系統自帶的防火牆,命令如下:
# chkconfig --list | grep fire
SuSEfirewall2_init 0:off 1:off 2:off 3:off 4:off 5:off 6:off B:on
SuSEfirewall2_setup 0:off 1:off 2:off 3:off 4:off 5:off 6:off
可以看到B是on的狀態,下面的命令來進行關閉B.
(首先停止服務)
#service SuSEfirewall2_init stop
#service SuSEfirewall2_setup stop
(禁止開機啓動)
# chkconfig --level B SuSEfirewall2_init off
# chkconfig SuSEfirewall2_init off
以上兩條命令都可以關閉開機啓動,效果相同。
# chkconfig --level B SuSEfirewall2_setup off
# chkconfig SSuSEfirewall2_setup off
這樣就可以永久性關閉防火牆了.
備註:一般情況下,兩個服務都開機啓動,這時,應該先關閉SuSEfirewall2_setup,然後再關閉SuSEfirewall2_init。沒有什麼別的原因,只是因爲你不先關閉setup,你是關閉不了init服務的,拒絕關閉。
二、安裝zlib、openssl、openssh
[root@localhost soft]# tar -xf zlib-1.2.11.tar.gz
[root@localhost soft]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure --prefix=/usr/local/zlib
[root@localhost zlib-1.2.11]# make
[root@localhost zlib-1.2.11]# 【rpm -e --nodeps zlib】最好不要卸載,不然會出現很多問題,以下ssl和ssh也一樣。省略此步驟
[root@localhost zlib-1.2.11]# make install
[root@localhost zlib-1.2.11]# rpm -qa | grep openssl
rpm: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory //如果卸載了zlib,就會出現這樣的信息,使用下面的兩條命令
[root@localhost zlib-1.2.11]# 【echo '/usr/local/zlib/lib' >>/etc/ld.so.conf】
[root@localhost zlib-1.2.11]# 【ldconfig 】
[root@localhost zlib-1.2.11]# mv /usr/lib64/openssl/ /usr/lib64/openssl.old
[root@localhost zlib-1.2.11]# mv /usr/bin/openssl /usr/bin/openssl.old
[root@localhost zlib-1.2.11]# mv /etc/pki/ca-trust/extracted/openssl /etc/pki/ca-trust/extracted/openssl.old
[root@localhost zlib-1.2.11]# cp /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.10.old
[root@localhost zlib-1.2.11]# cp /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.10.old
[root@localhost zlib-1.2.11]# mv /etc/ssl /etc/ssl.old
[root@localhost zlib-1.2.11]# mv /usr/include/openssl /usr/include/openssl.old
以上有些在不同的操作系統上會有文件不存在的提示,直接忽略
[root@localhost zlib-1.2.11]# 【rpm -qa |grep openssl|xargs -i rpm -e --nodeps {}】最好不要卸載,不然會出現很多問題,以下ssh也一樣。省略此步驟
[root@localhost zlib-1.2.11]# cd ..
[root@localhost soft]# tar -xf openssl-1.0.2o.tar.gz
[root@localhost soft]# cd openssl-1.0.2o
[root@localhost openssl-1.0.2o]# ./config --prefix=/usr/local/openssl --openssldir=/etc/ssl
[root@localhost openssl-1.0.2o]# make depend
[root@localhost openssl-1.0.2o]# make
[root@localhost openssl-1.0.2o]# make install
[root@localhost openssl-1.0.2o]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.0.2o]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
以下兩條命令可以忽略。如果卸載了openssl,出現問題,可以執行以下兩條
【echo "/usr/local/openssl/lib" >> /etc/ld.so.conf】
【ldconfig 】
[root@localhost openssl-1.0.2o]# mv /etc/ssh /etc/ssh.old
openssh-askpass-5.3p1-111.el6.x86_64
[root@localhost openssl-1.0.2o]# 【rpm -qa |grep openssh|xargs -i rpm -e --nodeps {}】最好不要卸載,不然會出現很多問題。省略此步驟
[root@localhost openssl-1.0.2o]# cd ..
[root@localhost soft]# tar -xf openssh-7.7p1.tar.gz
[root@localhost soft]# cd openssh-7.7p1
[root@localhost openssh-7.7p1]# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-md5-passwords --with-pam --without-hardening && make && make install
[root@localhost openssh-7.7p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd //此步奏會根據操作系統不同選用的文件不同,例如suse:#cp contrib/suse/rc.sshd /etc/init.d/sshd
[root@localhost openssh-7.7p1]# chmod +x /etc/init.d/sshd
[root@localhost openssh-7.7p1]# vi /etc/init.d/sshd
修改SSHD路徑(redhat,centos)
#SSHD=/usr/sbin/sshd
SSHD=/usr/local/openssh/sbin/sshd
#/usr/bin/ssh-keygen -A
/usr/local/openssh/bin/ssh-keygen -A
修改SSHD路徑(suse)
#SSHD_BIN=/usr/sbin/sshd
SSHD_BIN=/usr/local/openssh/sbin/sshd
#ssh-keygen -A
/usr/local/openssh/bin/ssh-keygen -A
[root@localhost ~]# vi /etc/ssh/sshd_config
PermitRootLogin yes
[root@localhost ~]# mv /usr/bin/ssh /usr/bin/ssh.old
[root@localhost ~]# ln -s /usr/local/openssh/bin/ssh /usr/bin/ssh
[root@localhost openssh-7.7p1]# chkconfig --add sshd
[root@localhost openssh-7.7p1]# chkconfig --list |grep sshd
sshd 0:關閉1:關閉2:啓用3:啓用4:啓用5:啓用6:關閉
[root@localhost openssh-7.7p1]# chkconfig sshd on
[root@localhost openssh-7.7p1]# service sshd restart
[root@localhost ~]# ssh -v
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[root@localhost ~]# ssh -46AaCfGgKkMNnqsTtVvXxYy
OpenSSH_7.7p1, OpenSSL 1.0.2o 27 Mar 2018
三、結尾
此時,測試好openssh可以正常連接了,就可以卸載掉telnet了,不然又會出現好多漏洞,爲了以防萬一,可以stop掉telnet,不要加入開機啓動,需要的時候直接start就可正常使用了。
[root@localhost ~]# mv /etc/securetty.old /etc/securetty
[root@localhost ~]# chkconfig xinetd off
[root@localhost ~]# service xinetd stop
停止 xinetd: [確定]
[root@localhost ~]# rpm -qa | grep telnet
telnet-0.17-48.el6.x86_64
telnet-server-0.17-48.el6.x86_64
[root@localhost ~]# rpm -qa | grep telnet|xargs -i rpm -e --nodeps {}
warning: /etc/xinetd.d/telnet saved as /etc/xinetd.d/telnet.rpmsave
[root@localhost ~]# rpm -qa | grep telnet
[root@localhost ~]# exit
四、使用ftp製作局域網yum源
有的時候好多同類型的機器會用到鏡像文件,一臺一臺的上傳或者插光盤比較麻煩,這時候就該局域網yum上場了
yum install vsftpd
service vsftpd start
mount /dev/cdrom /var/ftp/pub
ftp服務器上掛載好之後,在其他機器上配置yum文件便可使用了
vi /etc/yum.repos.d/yum.repo
[a]
name=a
baseurl=ftp://192.168.56.102/pub
enabled=1
gpgcheck=0
背景:
之前剛剛將服務器上的低版本openssh升級爲openssh-7.7p1,沒過多久openssh-v7.8之下的版本全都爆出了大量的漏洞,不得已只好在原來升級之後的基礎上再升級,直接升級到最新的openssh-v7.9p1.
1、下載源碼安裝包
【1】openssl下載地址:https://www.openssl.org/source/
根據需要選擇下載相應的版本,openssh v7.9版本要求openssl版本最低爲openssl v1.1
【目標】:openssl-1.1.0j.tar.gz(openssl-1.1.1a.tar.gz嘗試了多次不成功)
【2】perl 下載地址:http://www.cpan.org/src/
根據需要選擇下載相應的版本,openssl v1.1版本要求perl版本最低爲perl v5.10
【目標】:perl-5.10.0.tar.gz
【3】openssh下載地址:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/
根據需要選擇下載相應的版本,opensh目前最新版本爲openssh v7.9p1
【目標】:openssh-7.9p1.tar.gz
2、安裝源碼包
【1】安裝perl-5.10.0.tar.gz
# tar -xf perl-5.10.0.tar.gz
# cd perl-5.10.0/
#./configure.gnu -des -Dprefix=/usr/local/perl
#make
#make test
#make install
#/usr/local/perl/bin/perl -v
This is perl, v5.26.3 built for i686-linux
#perl -v
This is perl, v5.8.8 built for i386-linux-thread-multi
#mv /usr/bin/perl /usr/bin/perl.old
#ln -s /usr/local/perl/bin/perl /usr/bin/perl
#perl -v
This is perl, v5.26.3 built for i686-linux
【2】安裝openssl-1.1.1a.tar.gz
# mv /usr/lib64/openssl/ /usr/lib64/openssl.old
# mv /usr/bin/openssl /usr/bin/openssl.old
# mv /etc/pki/ca-trust/extracted/openssl /etc/pki/ca-trust/extracted/openssl.old
# mv /etc/ssl /etc/ssl.old
# mv /usr/include/openssl /usr/include/openssl.old
以上有些在不同的操作系統上會有文件不存在的提示,直接忽略
# tar -xf openssl-1.1.0j.tar.gz
# cd openssl-1.1.0j/
# ./config --prefix=/usr/local/openssl --openssldir=/etc/ssl
# make depend
# make
# make install
# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
以下兩條命令可以忽略。如果卸載了openssl,出現問題,可以執行以下兩條
【echo "/usr/local/openssl/lib" >> /etc/ld.so.conf】
【ldconfig 】
【3】安裝openssh-7.9p1.tar.gz
#mv /etc/ssh /etc/ssh.old
#tar -xf openssh-7.9p1.tar.gz
#cd openssh-7.9p1/
# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-md5-passwords --with-pam --without-hardening && make && make install
# cp contrib/redhat/sshd.init /etc/init.d/sshd //此步奏會根據操作系統不同選用的文件不同,例如suse:
#cp contrib/suse/rc.sshd /etc/init.d/sshd
#chmod +x /etc/init.d/sshd
# vi /etc/init.d/sshd
修改SSHD路徑(redhat,centos)
#SSHD=/usr/sbin/sshd
SSHD=/usr/local/openssh/sbin/sshd
#/usr/bin/ssh-keygen -A
/usr/local/openssh/bin/ssh-keygen -A
修改SSHD路徑(suse)
#SSHD_BIN=/usr/sbin/sshd
SSHD_BIN=/usr/local/openssh/sbin/sshd
#ssh-keygen -A
/usr/local/openssh/bin/ssh-keygen -A
# vi /etc/ssh/sshd_config
PermitRootLogin yes
# mv /usr/bin/ssh /usr/bin/ssh.old
# ln -s /usr/local/openssh/bin/ssh /usr/bin/ssh
[root@localhost openssh-7.7p1]# chkconfig --add sshd
[root@localhost openssh-7.7p1]# chkconfig --list |grep sshd
sshd 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉
[root@localhost openssh-7.7p1]# chkconfig sshd on
[root@localhost openssh-7.7p1]# service sshd restart
# ssh -v
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
# ssh -46AaCfGgKkMNnqsTtVvXxYy]
OpenSSH_7.9p1, OpenSSL 1.1.0j 20 Nov 2018