下载源码
-
openssh下载地址:https://www.openssh.com/ftp.html
openssh-8.9p1.tar.gz -
openssl下载地址:https://www.openssl.org/source/
openssl-1.1.1v.tar.gz -
zlib下载地址: http://zlib.net/
zlib-1.2.13.tar.gz
卸载系统自带的 openssh
执行卸载命令:
rpm -e `rpm -qa | grep openssh` --nodeps
rm -f /etc/ssh/*
[注意]
不要重启 sshd 服务否则客户端连接工具不能远程连接linux,除非是在本机上操作。
编译安装
- 安装 gcc
yum install -y gcc
- 安装 zlib
tar -xvf zlib*.tar.gz
cd zlib*
./configure --prefix=/usr/local/zlib && make && make install
- 安装 openssl
tar -zxf openssl*.tar.gz
cd openssl*
./config --prefix=/usr/local/openssl -fPIC && make && make install
- 配置动态库
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig
- 安装 openssh
tar -zxvf openssh*.tar.gz
cd openssh*
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-md5-passwords --without-hardening && make && make install
- 修改 sshd 脚本文件
cp openssh*/contrib/redhat/sshd.init /etc/init.d/sshd
sed -i 's/\/usr\/sbin\/sshd/\/usr\/local\/openssh\/sbin\/sshd/g' /etc/init.d/sshd
sed -i 's/\/usr\/bin\/ssh-keygen/\/usr\/local\/openssh\/bin\/ssh-keygen/g' /etc/init.d/sshd
- 修改 sshd 配置文件允许 root 登录
vim /etc/ssh/sshd_config
PermitRootLogin yes
- 添加 openssh 环境变量
echo "OPENSSH_HOME=/usr/local/openssh" >> /etc/profile
echo "export PATH=\$OPENSSH_HOME/bin:\$PATH" >> /etc/profile
- 将 sshd 加入到系统服务
chkconfig --add sshd # 添加开机启动
reboot # 重启系统
- 查看 ssh 版本
ssh -V
OpenSSH_8.9p1, OpenSSL 1.1.1v 1 Aug 2023