参考: https://www.cnblogs.com/nmap/p/10779658.html
说明:
- 本文基于:CentOS 7.5 minimal环境安装测试通过
- 由于CentOS 7.5自带的openssl为OpenSSL 1.0.2k-fips版本,满足openssh-8.3版本的需求,所以不用安装openssl。
1. 安装依赖库
1.1. 挂载centos7的iso,并配置本地yum源
mkdir -p /mnt/iso75/
mount /dev/cdrom /mnt/iso75/
cd /etc/yum.repos.d/
rm -rf *
cat << EOF > iso75.repo
[base]
name=CentOS-$releasever - Base
baseurl=file:///mnt/iso75
gpgcheck=0
enable=1
EOF
yum makecache
1.2. 安装依赖库
yum -y install gcc automake autoconf libtool make zlib-devel pam-devel tcp_wrappers-devel openssl-devel
2. 安装telnet
2.1. 安装telnet
yum install xinetd telnet-server -y
2.2. 配置telnet
vi /etc/securetty 在文件结尾追加如下内容:
pts/0
pts/1
pts/2
pts/3
2.3. 启动telnet
systemctl start telnet.socket
systemctl start xinetd
2.4. 关闭防火墙
systemctl stop firewalld
3. telnet连接到服务器
telnet连接到服务器,后续操作都在telnet中完成
4. 安装openssl 1.1.1g
4.1. 下载openssl
从 https://ftp.openssl.org/source/ 下载openssl-1.1.1g.tar.gz
4.2. 备份openssl
mv /usr/bin/openssl /usr/bin/openssl_bak
mv /usr/include/openssl /usr/include/openssl_bak
4.3. cd 到解压后的 openssl-1.1.1g 目录
tar -xvf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
4.4. 配置并安装
./config shared
make
make install
4.5. 创建软链接
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl /usr/include/openssl
4.6. 命令行执行下面2个命令加载新配置
echo "/usr/local/lib64" >> /etc/ld.so.conf
/sbin/ldconfig
4.7. 查看确认版本。没问题
openssl version
5. 安装openssh-8.3p1
5.1. 下载安装包
首先从 http://www.openssh.com/portable.html 的列表中找个速度快的,下载openssh-8.3p1.tar.gz文件。 下载完成后,将包上传到服务器并解压
5.2. 解压并跳转到openssh-8.3p1目录
tar -xvf openssh-8.3p1.tar.gz
cd openssh-8.3p1
5.3. 配置编译
配置编译(注意这里的/root/openssl-1.1.1g是我安装openssl的时候解压openssl-1.1.1g.tar.gz后的路径,而不是ssl安装后的路径):
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/root/openssl-1.1.1g --with-zlib --with-md5-passwords --with-pam
5.4. 删除旧的ssh配置
rm -rf /etc/ssh/*
5.5. 执行安装
make && make install
5.6. 设置sshd参数
vi /etc/ssh/sshd_config 设置以下参数
PermitRootLogin yes
UsePAM yes
UseDNS no
5.7. 删除旧的服务配置
rm -rf /usr/lib/systemd/system/sshd.service
5.8. 从原先的解压的包中拷贝一些文件到目标位置
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
chmod +x /etc/init.d/sshd
5.9. 配置并启动新的sshd服务
chkconfig --add sshd
systemctl enable sshd
chkconfig sshd on
systemctl restart sshd
6. 关闭telnet服务
6.1. 测试ssh成功后关闭telnet服务
systemctl stop xinetd.service
systemctl stop telnet.socket