查看版本
[root@KylinV10 ~]# ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f 31 Mar 2020
升级openssl
#解压gz包
tar -zxvf openssl-3.4.1.tar.gz
#进入到文件夹
cd openssl-3.4.2/
# 1. 回到源码目录
cd /root/openssl-3.4.2
# 2. 重新配置(共享库 + 安装前缀)
make distclean
./config shared zlib -fPIC --prefix=/usr/local/openssl
# 3. 编译 & 安装
make -j$(nproc)
make install
# 4. 确认库已生成
~~错误ls -l /usr/local/openssl/lib/libcrypto.so.3~~
ls -l /usr/local/openssl/lib64/libcrypto.so.3
# 5. 注册到系统缓存
echo '/usr/local/openssl/lib64' > /etc/ld.so.conf.d/openssl-3.4.2.conf
ldconfig
··························································
# 1. 修正路径
echo '/usr/local/openssl/lib64' > /etc/ld.so.conf.d/openssl-3.4.2.conf
# 2. 刷新缓存
ldconfig
# 3. 验证系统已识别
ldconfig -p | grep libcrypto.so.3
必须出现:
libcrypto.so.3 (libc6,x86-64) => /usr/local/openssl/lib64/libcrypto.so.3
查看openssl版本
openssl version
然后再回到 openssh 目录:
cd /root/openssh-10.0p1
make distclean
export PATH="/usr/local/openssl/bin:$PATH"
export PKG_CONFIG_PATH="/usr/local/openssl/lib64/pkgconfig"
./configure \
--prefix=/usr/local/openssh \
--sysconfdir=/etc/ssh \
--with-ssl-dir=/usr/local/openssl \
--with-zlib --with-pam
configure 已经 顺利通过!
下一步直接编译安装即可:
make -j$(nproc)
make install
1.停用旧服务
systemctl stop sshd
systemctl disable sshhd
systemctl daemon-reload
- 删掉系统 unit(不管有没有)
rm -f /usr/lib/systemd/system/ssh*.service
- 建新版配置目录 & 最小配置
mkdir -p /etc/ssh # 新版配置统一放这里
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
# 最小必改项(麒麟 V10 必须)
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^#PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
- 生成主机密钥(一次即可)
/usr/local/openssh/bin/ssh-keygen -A
- 写 systemd 单元(麒麟 V10 通用)
cat >/etc/systemd/system/sshd.service <<'EOF'
[Unit]
Description=OpenSSH Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/openssh/sbin/sshd -D -f /etc/ssh/sshd_config
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=42s
[Install]
WantedBy=multi-user.target
EOF
- 注册 & 启动
systemctl daemon-reload
systemctl enable --now sshd
- 验证(另开终端)
ssh -V # 客户端版本
ssh 127.0.0.1 # 本机再开一个会话,确认能登录
- 可选:保留旧二进制当救命稻草
mv /usr/sbin/sshd /usr/sbin/sshd.bak
ln -s /usr/local/openssh/sbin/sshd /usr/sbin/sshd
- 系统变量
echo 'export PATH=/usr/local/openssh/bin:$PATH' >> /etc/profile
source /etc/profile
验证(另开终端)
ssh -V
ssh 127.0.0.1
评论 (0)