1.环境准备:
OS系统:redhat 7.4
2.备份配置文件:
cp -rf /etc/ssh /etc/ssh.bak
cp -rf /usr/bin/openssl /usr/bin/openssl.bak
cp -rf /etc/pam.d /etc/pam.d.bak
cp -rf /usr/lib/systemd/system /usr/lib/systemd/system.bak
3.安装GCC编译器
GCC离线安装包如下:
我们可以按照下列顺序依次安装:
rpm -ivh mpfr-3.1.1-4.el7.x86_64.rpm
rpm -ivh libmpc-1.0.1-3.el7.x86_64.rpm
rpm -ivh kernel-headers-3.10.0-862.el7.x86_64.rpm
rpm -ivh glibc-headers-2.17-222.el7.x86_64.rpm
rpm -ivh glibc-devel-2.17-222.el7.x86_64.rpm
rpm -ivh cpp-4.8.5-28.el7.x86_64.rpm
rpm -ivh gcc-4.8.5-28.el7.x86_64.rpm
也可以直接用这一条rpm -ivh *.rpm --nodeps --force安装
安装完成后,用gcc -v验证
4. 编译安装per(安装openssl需要)
安装包为:perl-5.34.0.tar.gz
解压:tar -zxvf perl-5.34.0.tar.gz
cd perl-5.34.0
安装配置:./Configure -des -Dprefix=/usr/local/perl
编译安装:make && make test && make install (这一步在make test步骤有点慢,大概15分钟左右)
添加环境变量:
echo "export PERL_HOME=/usr/local/perl" >> /etc/profile
echo "export PATH=\$PERL_HOME/bin:\$PATH" >> /etc/profile
source /etc/profile
版本验证:perl -v
5. 编译升级zlib
安装包为:zlib-1.3.1.tar.gz
解压:tar -zxvf zlib-1.3.1.tar.gz
安装配置:cd zlib-1.3.1 && ./configure --prefix=/usr/local/zlib
编译:make -j 2
测试软件:make test
安装:make install
添加库文件:echo '/usr/local/zlib/lib' >> /etc/ld.so.conf.d/zlib.conf
ldconfig -v
6. 编译升级openssl
安装包为:openssl-1.1.1v.tar.gz
解压:tar -zxvf openssl-1.1.1v.tar.gz
安装配置:cd openssl-1.1.1v && ./config --prefix=/usr/local/openssl -d shared
编译:make -j 2
安装:make install
添加库文件:echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v |grep ssl
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
openssl version
7. 编译安装openssh
安装包为:openssh-9.8p1.tar.gz
解压安装包:tar -zxvf openssh-9.8p1.tar.gz
卸载旧的sshd服务(切记不能重启或者关掉远程工具):yum remove openssh
配置安装:cd openssh-9.8p1 && ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl/ --with-zlib=/usr/local/zlib
编译以及安装:make -j 4 && make install
cp contrib/redhat/sshd.init /etc/init.d/sshd
ll /etc/init.d/
chkconfig --add sshd
配置文件修改:
echo "X11Forwarding yes" >> /etc/ssh/sshd_config
echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
echo "XAuthLocation /usr/bin/xauth" >> /etc/ssh/sshd_config
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
将新的配置复制到指定目录:
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
版本验证:ssh -V
sshd服务重启:systemctl restart sshd
systemctl status sshd
reboot重启服务器后能再次连接,查看服务正常systemctl status sshd
碰到的报错:在make install 安装openssh时碰到文件权限太大,需要用下面命令修改文件权限后再次make install
[root@localhost openssh-9.8p1]# chmod 600 /etc/ssh/ssh_host_rsa_key
[root@localhost openssh-9.8p1]# chmod 600 /etc/ssh/ssh_host_ecdsa_key
[root@localhost openssh-9.8p1]# chmod 600 /etc/ssh/ssh_host_ed25519_key