一、准备工作
上来先查一下iptables的状态和selinux的状态先检查一下xinetd之前有没有service xinetd status[root@master ~]# chkconfig --list |grep iptablesiptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@master ~]# chkconfig iptables off[root@master ~]# chkconfig --list |grep iptablesiptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off[root@master ~]# service iptables status[root@master ~]# service iptables stop[root@master ~]# vim /etc/selinux/config 7 SELINUX=disabled[root@master ~]# setenforce 0 二、安装telnet服务1.安装软件 # yum install gcc pam-devel zlib-devel # yum install telnet-server* telnet # yum install pam-devel2.启用telnet服务
# vi /etc/xinetd.d/telnet 将其中disable字段的yes改为no以启用telnet服务在结尾增加 # vi /etc/securettypts/0pts/1pts/2pts/3pts/4pts/5pts/6pts/7pts/8在此时使用终端用telnet连接上主机!!!!!!!# cp -rp /etc/securetty /etc/securetty.old #允许root用户通过telnet登录 # service xinetd start #启动telnet服务 # chkconfig xinetd on #使telnet服务开机启动,避免升级过程中服务器意外重启后无法远程登录系统chkconfig --list | grep xinetdxinetd 0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@master yum.repos.d]# service xinetd restartStopping xinetd: [ OK ]Starting xinetd: [ OK ]3.测试telnet能否正常登入系统这时连接上telnet以防后续步骤出现问题telnet出现问题连接不上需要做以下操作这时开启另外一个标签使用telnet 连接23号端口
CentOS release 6.8 (Final)Kernel 2.6.32-642.el6.x86_64 on an x86_64login: root
Password: Last login: Tue Apr 24 10:53:15 from 192.168.37.1[root@master ~]# [root@master ~]# 确保能够登录成功并且不要关闭这个telnet窗口留着当备用
三、升级OpenSSH
1.备份当前opensshmv /etc/ssh /etc/ssh.old mv /etc/init.d/sshd /etc/init.d/sshd.old2.卸载当前openssh
#rpm -qa | grep openssh openssh-askpass-5.3p1-117.el6.x86_64openssh-5.3p1-117.el6.x86_64openssh-clients-5.3p1-117.el6.x86_64openssh-server-5.3p1-117.el6.x86_64# rpm -e --nodeps openssh-5.3p1-117.el6.x86_64 # rpm -e --nodeps openssh-server-5.3p1-117.el6.x86_64注意:卸载过程中如果出现以下错误
!!!#####error reading information on service sshd: No such file or directoryerror: %preun(openssh-server-5.3p1-117.el6.x86_64) scriptlet failed, exit status 1 报这个错就用下面这条命令# rpm -e --noscripts openssh-server-5.3p1-117.el6.x86_64
# rpm -e --nodeps openssh-clients-5.3p1-117.el6.x86_64
# rpm -e --nodeps openssh-askpass-5.3p1-117.el6.x86_64 # rpm -qa | grep openssh 3.openssh安装前环境配置# install -v -m700 -d /var/lib/sshd # chown -v root:sys /var/lib/sshd 当前系统sshd用户已经存在的话以下不用操作 # groupadd -g 50 sshd # useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd -s /bin/false -u 50 sshd4.解压openssh_7.5p1源码并编译安装
# wget https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz# tar -zxvf openssh-7.5p1.tar.gz # cd openssh-7.5p1 # ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-openssl-includes=/usr --with-privsep-path=/var/lib/sshd######
PAM is enabled. You may need to install a PAM control filefor sshd, otherwise password authentication may fail.Example PAM control files can be found in the contrib/subdirectory这里不用管# make
# make installmake && make install######
返回这些信息ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519/usr/sbin/sshd -t -f /etc/ssh/sshd_config返回这些信息 5.openssh安装后环境配置# 在openssh编译目录执行如下命令 # install -v -m755 contrib/ssh-copy-id /usr/bin # install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1 # install -v -m755 -d /usr/share/doc/openssh-7.5p1 # install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.5p1 # ssh -V #验证是否升级成功6.启用OpenSSH服务
# 在openssh编译目录执行如下目录 # echo 'X11Forwarding yes' >> /etc/ssh/sshd_config # echo "PermitRootLogin yes" >> /etc/ssh/sshd_config #允许root用户通过ssh登录 # cp -p contrib/redhat/sshd.init /etc/init.d/sshd # chmod +x /etc/init.d/sshd # chkconfig --add sshd # chkconfig sshd on # chkconfig --list sshd sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off7.恢复原来的配置信息
# cp -rp /etc/securetty /etc/securetty.new# cp -rp /etc/securetty.old /etc/securetty 如需还原之前的ssh配置信息,可直接删除升级后的配置信息,恢复备份。# cp -rp /etc/ssh /etc/ssh.new# rm -rf /etc/ssh # cp -rp /etc/ssh.old /etc/ssh# vim /etc/ssh/ssh_config
50 #GSSAPIAuthentication yes #注释掉这一行 确保安全可以/GSS搜索注释所有带GSS的# vim /etc/ssh/sshd_config# 97 UsePAM no #去掉注释然后把参数改为no##注释掉下面三个参数81 #GSSAPIAuthentication yes83 #GSSAPICleanupCredentials yesPermitRootLogin yes 这个去掉注释启用并改成yes####需要考虑到防火墙重启会挡住端口要关闭防火墙相关的东西
重启一下sshd试试# service sshd restart !!!!!!!!!这里重启系统[root@master ~]# reboot这里重新连接服务器
一个ssh的连接 #注意端口号还是以前一个telnet的连接 端口号是23 到这里就结束了然后进行以下善后# vi /etc/xinetd.d/telnet 将其中disable字段的改为yes关闭telnet功能service xinetd stopchkconfig xinetd off 在结尾中删除以下内容# vi /etc/securettypts/0pts/1pts/2pts/3pts/4pts/5pts/6pts/7pts/8以前如果是开启防火墙的把防火墙开启
chkconfig iptables onservice iptables start