Centos6.5升级Openssh到7.9

##安装yum针对本机没有安装yum只有镜像的情况,如果镜像都没有,巧妇难为无米之炊)

cd /mnt/
mkdir centos6.5
mount -o loop -t iso9660 /home/dongruan/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/centos6.5/
cd /etc/yum.repos.d/
mkdir bk
mv *.repo bk
vi centos6.repo

----------------start----------------

[CentOS65]
name=CentOS65
baseurl=file:///mnt/centos6.5
enabled=1
gpgcheck=0
gpgkey=file:///mnt/centos6.5/RPM-GPG-KEY-CentOS-6

----------------ent------------------
yum list ##list显示出来 说明yum安装成功

##安装telnet(防止ssh升级或启动失败,连接不上服务器;可以通过telnet连接)

cd /mnt/centos6.5/Packages
rpm -i telnet-0.17-47.el6_3.1.x86_64.rpm
yum -y install telnet-server*

##升级SSH

service iptables stop
chkconfig iptables off
sed -i 's/\(.*\)disable\(.*\)/\ \ \ \ \ \ \ \ disable\ \ \ \ \ \ \ \ \ =\ no/g'   /etc/xinetd.d/telnet  ##将其中disable字段的yes改为no以启用telnet服务  
mv /etc/securetty /etc/securetty.old   #允许root用户通过telnet登录
service xinetd start
chkconfig xinetd on  #开23端口

yum install -y gcc openssl-devel pam-devel rpm-build pam-devel
#wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz
rpm -e `rpm -qa | grep openssh` --nodeps
cd /home/dongruan/ && tar zxvf openssh-7.9p1.tar.gz &&  cd openssh-7.9p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers && make && make install
#或手动修改PermitRootLogin no 修改为 PermitRootLogin yes 允许root远程登陆
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin\ yes/g' /etc/ssh/sshd_config
##禁止空密码
sed -i 's/#PermitEmptyPasswords\(.*\)/PermitEmptyPasswords\ no/g' /etc/ssh/sshd_config
##禁止selinux 否则重启后会登录失败
sed -i 's/^SELINUX\(.*\)/SELINUX=disabled/g' /etc/selinux/config
~~*##写上新版ssh支持的算法(其中ecdh-sha2-nistp521方法抛错 被我去掉了)
 ##原来: echo 'KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1' >> /etc/ssh/sshd_config*~~  

echo 'KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1' >> /etc/ssh/sshd_config
cp contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
service sshd start
service sshd restart
chkconfig --list sshd
ssh -V

mv /etc/securetty.old /etc/securetty   #允许root用户通过telnet登录
service xinetd stop
chkconfig xinetd off
service iptables start
chkconfig iptables on
将之前改过的disable=yes又改回去成no.
随后再将修改iptables将23端口关闭,并重启iptables服务.
至此,可以再开ssh登录,用ssh -V查看版本号.

你可能感兴趣的:(Openssh升级到7.9)