赞
踩
标准升级就是使用系统源自动更新最新版本,但是Centos7的rpm包只更新到了7.4版本
- #在线升级
- yum update openssh
-
-
- #离线升级
- rpm -Uvh openssh-7.4p1-22.el7_9.x86_64.rpm
补充:rpm包离线下载推荐网址:RPM Search
压缩包编译安装是linux系统下软件更新的第二种常用方式,软件厂家只需要提供压缩包的源码或者编译程序,适配各系统由用户自行编译,适合于各类系统安装升级
- #在线安装
- yum install telnet telnet-server xinetd -y
-
- #离线安装telnet-server
- 1-在有互联网的机器,提前缓存离线包,执行以下命令
- mkdir /home/telnet
- yum install telnet telnet-server xinetd --downloadonly --downloaddir=/home/telnet
-
- 2-将刚才下载的依赖文件夹的安装包拷贝到内网机器进行安装
- yum localinstall ./*.rpm -y
-
- #关闭防火墙和selinux
- systemctl stop firewalld.service
- systemctl disable firewalld.service
- setenforce 0
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
- sestatus
-
- #启动服务
- systemctl start telnet.socket
- systemctl start xinetd
- systemctl status telnet.socket
- systemctl status xinetd
- systemctl enable telnet.socket
- systemctl enable xinetd
-
- #重启服务
- echo 'pts/0' >>/etc/securetty
- echo 'pts/1' >>/etc/securetty
- systemctl restart telnet.socket
- systemctl restart xinetd
- systemctl status telnet.socket
- systemctl status xinetd
-
- #停止服务
- systemctl stop telnet.socket
升级前:OpenSSL 1.0.2k-fips 升级后:OpenSSL 1.1.1s(2022-12)
- openssl version
- which openssl
- #在线安装依赖
- yum -y install gcc gcc-c++ zlib zlib-devel perl pam-devel libXt libstdc++-devel
-
- #离线安装依赖
- 1-在有互联网的机器,提前缓存离线包,执行以下命令
- mkdir /home/yilai
- yum install gcc zlib zlib-devel gcc perl --downloadonly --downloaddir=/home/yilai
-
- 2-将刚才下载的依赖文件夹的安装包拷贝到内网机器进行安装
- yum localinstall ./*.rpm
注意:不同版本可能源文件的ssl路径不一样,不用在意,主要备份/usr/bin/openssl下即可
- #备份以前的文件
- #在/home下创建opensslbak作为备份文件夹
- mkdir -p /home/opensslbak
- cd /home/opensslbak
- ll /usr/bin/openssl
- ll /usr/include/openssl
- mv /usr/bin/openssl /home/opensslbak/
- mv /usr/lib64/libssl.so /home/opensslbak/
- mv /usr/include/openssl /home/opensslbak/
- #下载官网安装包-2022-12
- https://www.openssl.org/source/openssl-1.1.1s.tar.gz
- wget https://www.openssl.org/source/openssl-1.1.1s.tar.gz --no-check-certificate
-
- #解压并编译安装
- tar -xzvf openssl-1.1.1s.tar.gz
- cd openssl-1.1.1s/
- ./config --shared zlib
- make && make install
- #查看新生成文件夹
- ls /usr/local/bin/openssl
- ls /usr/local/include/openssl
- ls /usr/local/ssl
- ls /usr/local/lib64/
- ls /usr/local/lib64/libssl.so
- ls /usr/local/lib64/libcrypto.so
-
- #测试新命令可能会报错,稍后更新下库依赖路径ldconfig后就正常了
- /usr/local/bin/openssl version
- /usr/local/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
-
- #挂载新的文件
- ln -s /usr/local/bin/openssl /usr/bin/openssl
- ln -s /usr/local/include/openssl/ /usr/include/openssl
-
- ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
- ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
-
- echo "/usr/local/lib" >> /etc/ld.so.conf
- echo "/usr/local/lib64" >> /etc/ld.so.conf
- ldconfig
- ldconfig -v
-
- #写入新的依赖库路径
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64
- echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64" >> ~/.bashrc
- echo $LD_LIBRARY_PATH
-
- #测试是否正常更新
- bash
- openssl version
- OpenSSL 1.1.1s 1 Nov 2022
升级前:OpenSSH_7.4p1 升级后:OpenSSH_9.1p1
https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.1p1.tar.gz
- cd /home/
- wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.1p1.tar.gz --no-check-certificate
- tar xfz openssh-9.1p1.tar.gz
- chown -R root:root openssh-9.1p1
- cd ./openssh-9.1p1
-
- #备份ssh文件夹
- mkdir -pv /home/sshbak
- cp -arp /etc/ssh/ /home/sshbak/ssh
- cp /etc/ssh/sshd_config /home/sshbak/sshd_config.backup
- cp /etc/pam.d/sshd /home/sshbak/sshd.backup
- cp /etc/init.d/sshd /home/sshbak/sshd.old
- mv /etc/ssh /etc/ssholdbak
- ll /home/sshbak/
- cd ./openssh-9.1p1
-
- ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/include/openssl --with-ssl-dir=/usr/local/lib64 --with-zlib --with-md5-passwords --with-pam
- #./configure
- #--prefix=/usr
- #--sysconfdir=/etc/ssh #编译后ssh路径
- #--with-openssl-includes=/usr/local/include/openssl #有很多xxx.h的文件目录
- #--with-ssl-dir=/usr/local/lib64 #有xxx.so的目录
- #--with-zlib
- #--with-md5-passwords
- #--with-pam
-
- make && make install
-
- #升级完成
- ssh -V
#根据自己需要调整sshd配置文件,参考如下
- vim /etc/ssh/sshd_config
-
- 32 PermitRootLogin yes #允许root登录,root用户必须添加
- 41 AuthorizedKeysFile .ssh/authorized_keys #指定公钥文件的保存位置以及名称
- 57 PasswordAuthentication yes #允许密码验证
- 82 UsePAM yes #PAM模块
- 98 UseDNS no #关闭dns检测
- 109 Subsystem sftp /usr/libexec/sftp-server #开启SFTP并指定路径
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
- cp /etc/pam.d/sshd /etc/pam.d/sshd.bak
-
- cat > /etc/pam.d/sshd << 'EOF'
- #%PAM-1.0
- auth required pam_sepermit.so
- auth include password-auth
- account required pam_nologin.so
- account include password-auth
- password include password-auth
- # pam_selinux.so close should be the first session rule
- session required pam_selinux.so close
- session required pam_loginuid.so
- # pam_selinux.so open should only be followed by sessions to be executed in the user context
- session required pam_selinux.so open env_params
- session optional pam_keyinit.so force revoke
- session include password-auth
- EOF
- #mv /usr/bin/ssh-copy-id /home/sshbak/
- cd /home/openssh-9.1p1
- install -v -m755 contrib/ssh-copy-id /usr/bin
- ll /usr/bin/ssh-copy-id
开机自启网上有很多配置方法,结合博主实测,建议是自行学习后自定义开机systemd文件
- #进入ssh安装包的文件夹里面自带redhat系统的开机脚本
- cd /home/openssh-9.1p1
- cp -a contrib/redhat/sshd.init /etc/init.d/sshd.init
- chmod +x /etc/init.d/sshd.init
- /etc/init.d/sshd.init start
-
- #执行启动之后就会自动生成一个服务文件在run/systemd/generator.late/下
- ll /run/systemd/generator.late/sshd.init.service
- #修改脚本启动类型为simple,防止启动通知服务过程卡死
- vim /run/systemd/generator.late/sshd.init.service
-
- [Service]
- #类型修改Type=forking为simple,防止启动通知服务过程卡死
- Type=simple
- #超时时间可以改短一些
- TimeoutSec=30s
- #修改名称sshd.init.service为sshd9.service
- cp /run/systemd/generator.late/sshd.init.service /usr/lib/systemd/system/sshd9.service
- systemctl daemon-reload
- systemctl restart sshd9.service
- systemctl status sshd9.service
- systemctl enable sshd9.service
- cat /usr/lib/systemd/system/sshd9.service
-
-
- #配置开机自启,如果没有自启,手动挂载软链接开机自启
- ln -s /usr/lib/systemd/system/sshd9.service /etc/systemd/system/multi-user.target.wants/sshd9.service
- systemctl status sshd.service
- systemctl stop sshd.service
- systemctl disable sshd.service
-
- #检查是否配置成功
- systemctl list-unit-files | grep sshd9
- ls /etc/systemd/system/multi-user.target.wants | grep sshd9
- ls /usr/lib/systemd/system/ | grep sshd9
- openssl version && ssh -V
-
- #重启服务器
- reboot
- #查询scp
- whereis scp
-
- #备份scp
- mkdir /home/scpbak
- cp /usr/bin/scp /home/scpbak
-
- #取消权限
- chmod a-x /usr/bin/scp
-
- #重命名scp
- mv /usr/bin/scp /usr/bin/scpbak
● 老版本的服务需要先启动sshd-keygen.service
● 但是新版本编译没有这个服务相关文件,如果直接替换就会报错,需要删除
● 将Type=notify改为Type=simple,防止通知一直卡死系统
1、 9.1版本新编写sshdnew.service
- vim /usr/lib/systemd/system/sshdnew.service
-
- [Unit]
- Description=OpenSSH server daemon
- Documentation=man:sshd(8) man:sshd_config(5)
- After=network.target
-
- [Service]
- Type=simple
- ExecStart=/usr/sbin/sshd -D
- KillMode=process
- Restart=on-failure
- RestartSec=42s
-
- [Install]
- WantedBy=multi-user.target
2、 7.4版本sshd.service原版文件
- cat /usr/lib/systemd/system/sshd.service
-
- [Unit]
- Description=OpenSSH server daemon
- Documentation=man:sshd(8) man:sshd_config(5)
- After=network.target sshd-keygen.service
- Wants=sshd-keygen.service
-
- [Service]
- Type=notify
- EnvironmentFile=/etc/sysconfig/sshd
- ExecStart=/usr/sbin/sshd -D $OPTIONS
- ExecReload=/bin/kill -HUP $MAINPID
- KillMode=process
- Restart=on-failure
- RestartSec=42s
-
- [Install]
- WantedBy=multi-user.target
3、 7.4版本sshd-keygen.service文件
- vim /usr/lib/systemd/system/sshd-keygen.service
-
- [Unit]
- Description=OpenSSH Server Key Generation
- ConditionFileNotEmpty=|!/etc/ssh/ssh_host_rsa_key
- ConditionFileNotEmpty=|!/etc/ssh/ssh_host_ecdsa_key
- ConditionFileNotEmpty=|!/etc/ssh/ssh_host_ed25519_key
- PartOf=sshd.service sshd.socket
-
- [Service]
- ExecStart=/usr/sbin/sshd-keygen
- Type=oneshot
- RemainAfterExit=yes
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。