
一、升级前操作
1、实验环境
2、升级安装包准备
3、配置本地安装源(可选)
cd etc/yum.repos.d/mkdir bakmv CentOS-* bak/mkdir mnt/cdrommount opt/CentOS-7-x86_64-DVD-*.iso mnt/cdrom/mount dev/sr0 mnt/cdromecho '[local]' >> etc/yum.repos.d/local.repoecho 'name=local' >> etc/yum.repos.d/local.repoecho 'baseurl=file:///mnt/cdrom' >> etc/yum.repos.d/local.repoecho 'gpgcheck=0' >> etc/yum.repos.d/local.repoecho 'enable=1' >> etc/yum.repos.d/local.repoyum makecache fast
4、安装依赖包
yum groupinstall -y "Development Tools"yum install -y xinetd telnet-server pam pam-devel
5、使用telnet登录
useradd -m localuser ; echo 'password' | passwd --stdin localuser
systemctl enable xinetd.servicesystemctl enable telnet.socketsystemctl start telnet.socketsystemctl start xinetd
netstat -lntp | grep -w 23iptables-save > iptables.bak`date +%Y%m%d`iptables -I INPUT -p tcp --dport 23 -j ACCEPTiptables -nL | grep 23//或者firewall-cmd --zone=public --add-port=23/tcp --permanentfirewall-cmd --reload
二、原版本为PRM的操作步骤
1、查看升级前的情况
cat etc/*-release >> before_update.outssh -V >> before_update.outopenssl version -a >> before_update.outrpm -qa | grep openssh >> before_update.outrpm -qa | grep openssl >> before_update.outrpm -qa | grep zlib >> before_update.out
2、设置环境变量
zlib_version=1.2.11ssl_version=1.0.2tssh_version=8.1p1umask 022
3、安装zlib
cd usr/local/src/ && \tar zxf zlib-$zlib_version.tar.gz && \cd zlib-$zlib_version/ && \./configure --prefix=/usr/local/zlib && \make -j4 && make install && \chmod -R 755 usr/local/zlib
4、安装openssl
cd usr/local/src/ && \tar zxf openssl-$ssl_version.tar.gz && \cd openssl-$ssl_version/ && \./config shared && \make -j4 && make test && make install && \echo "/usr/local/ssl/lib" >> etc/ld.so.conf && \ldconfig && \mv usr/bin/openssl usr/bin/openssl.bak`date +%Y%m%d` && \ln -s usr/local/ssl/bin/openssl usr/bin/openssl && \ln -s usr/local/ssl/include/openssl usr/include/openssl && \chmod -R 755 /usr/local/ssl && \openssl version -a //新版本信息
5、备份openssh
6、关闭sshd服务并卸载openssh
7、安装openssh
cd /usr/local/src/ && \tar zxf openssh-$ssh_version.tar.gz && \cd openssh-$ssh_version/ && \./configure --prefix=/usr/local/openssh-$ssh_version --sysconfdir=/etc/ssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl --with-pam --with-tcp-wrappers --with-md5-passwords && \chmod 0600 /etc/ssh/ssh_host_rsa_key && \chmod 0600 /etc/ssh/ssh_host_ecdsa_key && \chmod 0600 /etc/ssh/ssh_host_ed25519_key && \make -j4 && make install && \chmod -R 755 /usr/local/openssh-$ssh_version && \/usr/local/openssh-$ssh_version/bin/ssh -V //新版本信息
8、修改默认路径
echo $PATH && \echo "export PATH=/usr/local/openssh-$ssh_version/sbin:/usr/local/openssh-$ssh_version/bin:\$PATH" >> /etc/profile && \source /etc/profile && \echo $PATH
9、复制可执行文件
//复制新执行文件到系统路径cp -a /usr/local/openssh-$ssh_version/bin/* /usr/bin/cp -a /usr/local/openssh-$ssh_version/sbin/sshd /usr/sbin/sshd//复制启动文件echo y | cp /usr/local/src/openssh-$ssh_version/contrib/redhat/sshd.init /etc/init.d/sshd
10、启动sshd服务
systemctl daemon-reloadsystemctl start sshdchkconfig sshd on
三、原版本为源码的操作步骤
1、设置环境变量
zlib_version=1.2.11ssl_version=1.1.1gssh_version=8.3p1ssh_old_version=8.1p1umask 022
2、安装zlib(可选)
cd /usr/local/src/ && \tar zxf zlib-$zlib_version.tar.gz && \cd zlib-$zlib_version/ && \./configure --prefix=/usr/local/zlib && \make -j4 && make install && \chmod -R 755 /usr/local/zlib
cp -a /usr/local/ssl /usr/local/ssl.`date +%Y%m%d`cd /usr/local/src/ && \tar zxf openssl-$ssl_version.tar.gz && \cd openssl-$ssl_version/ && \./config shared && \make -j4 && make test && make install && \chmod -R 755 /usr/local/ssl && \echo "/usr/local/lib64" >> /etc/ld.so.conf && \ldconfig && \openssl version -a //新版本信息
4、关闭openssh服务
systemctl stop sshd
cd /usr/local/src/ && \tar zxf openssh-$ssh_version.tar.gz && \cd openssh-$ssh_version/ && \./configure --prefix=/usr/local/openssh-$ssh_version --sysconfdir=/etc/ssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl --with-pam --with-tcp-wrappers --with-md5-passwords && \chmod 0600 /etc/ssh/ssh_host_rsa_key && \chmod 0600 /etc/ssh/ssh_host_ecdsa_key && \chmod 0600 /etc/ssh/ssh_host_ed25519_key && \make -j4 && make install && \chmod -R 755 /usr/local/openssh-$ssh_version && \/usr/local/openssh-$ssh_version/bin/ssh -V
export PATH=`echo $PATH | sed "s#/usr/local/openssh-$ssh_old_version/sbin:/usr/local/openssh-$ssh_old_version/bin:##g"`echo $PATH
7、将/etc/profile里openssh旧版本的行注释掉
sed -i "/openssh-$ssh_old_version/s/^/#/g" /etc/profilegrep openssh-$ssh_old_version /etc/profile
8、修改默认路径
echo $PATH && \echo "export PATH=/usr/local/openssh-$ssh_version/sbin:/usr/local/openssh-$ssh_version/bin:\$PATH" >> /etc/profile && \source /etc/profile && \echo $PATH
9、复制可执行文件
//备份旧执行文件:for i in $(cd /usr/local/openssh-$ssh_version/bin/;ls );domv /usr/bin/$i /usr/bin/$i.bak`date +%Y%m%d`donemv /usr/sbin/sshd /usr/sbin/sshd.bak`date +%Y%m%d`//复制新执行文件到系统路径cp -a /usr/local/openssh-$ssh_version/bin/* /usr/bin/cp -a /usr/local/openssh-$ssh_version/sbin/sshd /usr/sbin/sshd//复制启动文件echo y | cp /usr/local/src/openssh-$ssh_version/contrib/redhat/sshd.init /etc/init.d/sshd
10、启动sshd服务
systemctl daemon-reloadsystemctl restart sshdchkconfig sshd on
四、升级后操作
1、版本信息验证
ssh -Vssh localuser@localhost ssh -V
2、关闭telnet服务
systemctl disable xinetd.servicesystemctl disable telnet.socketsystemctl stop telnet.socketsystemctl stop xinetdnetstat -lntp | grep -w 23
3、其它配置
## 配置不允许root登录sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/g' /etc/ssh/sshd_config## 配置允许root登录sed -i 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
五、报错及解决方法
报错1
checking for openssl/opensslv.h... yeschecking OpenSSL header version... 1000214f (OpenSSL 1.0.2t 10 Sep 2019)checking for OpenSSL_version... nochecking for OpenSSL_version_num... nochecking OpenSSL library version... 100020bf (OpenSSL 1.0.2k 26 Jan 2017)checking whether OpenSSL''s headers match the library... noconfigure: error: Your OpenSSL headers do not match yourlibrary. Check config.log for details.If you are sure your installation is consistent, you can disable the checkby running "./configure --without-openssl-header-check".Also see contrib/findssl.sh for help identifying header/library mismatches.或者:checking OpenSSL header version... not foundconfigure: error: OpenSSL version header not found.
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf && \ldconfig && \mv /usr/bin/openssl /usr/bin/openssl.bak`date +%Y%m%d` && \mv /usr/include/openssl /usr/include/openssl.bak`date +%Y%m%d` && \ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl && \ln -s /usr/local/ssl/include/openssl /usr/include/openssl
报错2
configure: error: PAM headers not found
yum install -y pam-devel
报错3
PAM is enabled. You may need to install a PAM control file for sshd, otherwise password authentication may fail.Example PAM control files can be found in the contrib/ subdirectory
报错4
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: UNPROTECTED PRIVATE KEY FILE! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.It is required that your private key files are NOT accessible by others.This private key will be ignored.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: UNPROTECTED PRIVATE KEY FILE! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Permissions 0640 for '/etc/ssh/ssh_host_ecdsa_key' are too open.It is required that your private key files are NOT accessible by others.This private key will be ignored.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: UNPROTECTED PRIVATE KEY FILE! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.It is required that your private key files are NOT accessible by others.This private key will be ignored.sshd: no hostkeys available -- exiting.make: [check-config] Error 1 (ignored)
chmod 600 /etc/ssh/ssh_host_rsa_keychmod 600 /etc/ssh/ssh_host_ecdsa_keychmod 600 /etc/ssh/ssh_host_ed25519_key然后,重新 make install
报错5
$ ssh -Vssh: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory
chmod -R 755 /usr/local/zlibchmod -R 755 /usr/local/sslchmod -R 755 /usr/local/openssh-8.1p1
报错6
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
是在openssl覆盖升级完成后,执行 openssl version -a 报的错;
文章转载自kpxiaoxm,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




