# 查看当前版本
ssh -V
1
# 下载升级文件
wget http://www.zlib.net/zlib-1.2.12.tar.gz
wget https://www.openssl.org/source/openssl-3.0.5.tar.gz
wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz
1
2
3
2
3
# 备份原始配置文件
cp /etc/ld.so.conf /etc/ld.so.conf.bak
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/bin/ssh /usr/bin/ssh.bak
cp /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 编译安装zlib
tar --no-same-owner -zxvf zlib-1.2.12.tar.gz
cd zlib-1.2.12
./configure --prefix=/usr/local/zlib
make -j4 && make install
echo '/usr/local/zib/lib' >> /etc/ld.so.conf
ldconfig -v
1
2
3
4
5
6
2
3
4
5
6
# 编译安装openssl
yum install perl-CPAN #安装环境需要的 IPC/Cmd.pm 模块
perl -MCPAN -e shell #全部选择默认配置,高手请根据提示自行选择
# 在shell中安装缺少的模块
cpan[1]> install IPC/Cmd.pm
tar --no-same-owner -zxvf openssl-3.0.5.tar.gz
cd openssl-3.0.5
./config --prefix=/usr/local/ssl3 -d shared
make -j4 && make install
echo '/usr/local/ssl3/lib64' >> /etc/ld.so.conf
ldconfig -v
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 编译安装openssh
tar --no-same-owner -zxvf openssh-9.0p1.tar.gz
cd openssh-9.0p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl3 --with-pam --with-md5-passwords
make -j4 && make install
# 配置
echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 设置新的文件
rm -rf /usr/sbin/sshd
rm -rf /usr/bin/ssh
rm -rf /usr/bin/ssh-keygen
rm -rf /etc/ssh/ssh_host_ecdsa_key.pub
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 检查配置并重新启动服务
sshd -t
systemctl restart sshd
1
2
2
# 还原配置
rm -rf /usr/sbin/sshd && cp /usr/sbin/sshd.bak /usr/sbin/sshd
rm -rf /usr/bin/ssh && cp /usr/bin/ssh.bak /usr/bin/ssh
rm -rf /usr/bin/ssh-keygen && cp /usr/bin/ssh-keygen.bak /usr/bin/ssh-keygen
rm -rf /etc/ssh/ssh_host_ecdsa_key.pub && cp /etc/ssh/ssh_host_ecdsa_key.pub.bak /etc/ssh/ssh_host_ecdsa_key.pub
rm -rf /etc/ld.so.conf && cp /etc/ld.so.conf.bak /etc/ld.so.conf
ldconfig -v
1
2
3
4
5
6
2
3
4
5
6
# 查看系统最新日志
tail -n 100 /var/log/message
1