本文参考:https://www.cnblogs.com/wenxiao1-2-3-4/p/16481300.html

#!/bin/sh


cd /etc/yum.repos.d

mkdir backup

mv Cent* backup

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-9.repo

yum -y clean all

yum -y makecache  #以上设置云源



cd /tmp

mkdir update

cd update

wget --no-check-certificate https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.4p1.tar.gz

tar xf openssh-9.4p1.tar.gz

yum -y install zlib zlib-devel perl openssl-devel

yum -y install gcc gcc-c++

mv /etc/ssh /etc/ssh.bak

cd /tmp/update/openssh-9.4p1

mkdir /usr/local/openssh

cd /tmp/update/openssh-9.4p1

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/include --with-ssl-dir=/usr/local/bin/openssl --with-zlib --with-md5-passwords --without-openssl-header-check

#centos7是下面

#./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/include --with-ssl-dir=/usr/local/bin/openssl --with-zlib --with-md5-passwords --without-openssl-header-check



make

make install

echo "UseDNS no" >> /etc/ssh/sshd_config

echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config

echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config

echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config

echo "X11Forwarding yes" >> /etc/ssh/sshd_config

#echo "X11UseLocalhost no" >> /etc/ssh/sshd_config  

echo "XAuthLocation /usr/bin/xauth" >> /etc/ssh/sshd_config

mv /usr/sbin/sshd /usr/sbin/sshd0909

mv /usr/bin/ssh /usr/bin/ssh0909

mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen0909

ln -s /usr/local/openssh/bin/ssh /usr/bin/ssh

ln -s /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

ln -s /usr/local/openssh/sbin/sshd /usr/sbin/sshd

ssh -V

mv /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.service.bak

cp -arf ./contrib/redhat/sshd.init /etc/rc.d/init.d/sshd

cp -arf ./contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

chkconfig --add sshd

systemctl enable sshd --now

systemctl restart sshd


/etc/rc.d/init.d/sshd目录加入启动脚本后,systemctl start sshd 如识别不到,请尝试关闭selinux 或者重启系统尝试,执行启动脚本后报错误如下:

 

centos9升级openssh 9.4p1_linux

查看文件/etc/rc.d/init.d/sshd 文件49行,文件如下

centos9升级openssh 9.4p1_启动脚本_02

 

 将编译后的配置文件拷贝到 /etc/ssh/下,重新执行,仍然报错。查看脚本第一行发现缺少文件

centos9升级openssh 9.4p1_重启_03

 

 拷贝centos7.6版本的functions 文件上传,重新启动后成功

可从cnetos7系列系统中/etc/init.d/目录提取,这里我上传了一个我使用的文件


如ssh启动不了,如下:

#关闭selinux     vi /etc/selinux/config  手工

#修改SELINUX=enforce为SELINUX=disable  重启服务器后

restorecon -r -v /root/.ssh

#开启selinux    vi /etc/linux/config  手工

#修改为SELINUX=enforcing

systemctl start sshd