Centos7 隐藏ssh(OpenSSH) 版本号

参考:https://www.yangliuan.cn/?p=1090

1.安装所需工具

yum install --downloadonly --downloaddir=rpm gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel krb5-devel
yum -y install zlib zlib-devel
yum -y install libstdc++-devel-4.8.5-44.el7.x86_64

2.下载 ssh安装包以及ssl

wget -c http://120.79.180.193/ttt/openssl-1.1.1g.tar.gz
wget -c http://120.79.180.193/ttt/openssh-8.2p1.tar.gz

3.备份ssl文件

mv /usr/bin/openssl /usr/bin/openssl_bak 
mv /usr/include/openssl /usr/include/openssl_bak

4.解压缩ssl 压缩包、以及编译安装

tar -zxvf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g/
./config --prefix=/usr/local/ssl -d shared && make -j 4 && make install
echo $?

5.创建ssl软连接

ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl

 ll /usr/bin/openssl
 ll /usr/include/openssl -ld

6.查看ssl版本号

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
openssl version

如果报错openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

查找libssl.so.1.1的目录 然后生成软链接

find / -name "libssl.so.1.1"
/usr/local/lib64/libssl.so.1.1
find / -name "libcrypto.so.1.1"
/usr/local/lib64/libcrypto.so.1.1

ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

再次查看版本号

openssl version #查看确认版本

ssl 安装完成

开始安装openssh

1.查看ssh版本

ssh -V 
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017

2.备份ssh配置文件

mv /etc/ssh/ /opt

3.解压openssh安装包,以及编译安装

tar -zxvf openssh-8.2p1.tar.gz
cd openssh-8.2p1
./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl   --with-zlib   --with-md5-passwords   && make -j 4 && make install

  #如果遇到权限问题 permission 0640 for xxxx 将报权限问题的目录都设为

  600 chmod -R 0600 /etc/ssh/ssh_host_ecdsa_key

4.修改sshd配置

 echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
 echo "UseDNS no" >> /etc/ssh/sshd_config

5.从安装目录cp文件到目标位置

cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

6.设置执行权限

chmod +x /etc/init.d/sshd

7.添加启动项

chkconfig --add sshd
systemctl enable sshd

8.把原先的systemd管理的sshd文件删除或者移走或者删除,不移走的话影响我们重启sshd服务

mv /usr/lib/systemd/system/sshd.service /tmp/

9.设置开机启动

chkconfig sshd on

10.重启sshd、查看启动状态

systemctl restart sshd.service
systemctl status sshd.service

11.查看ssh 22端口是否启动

netstat -ulntp

12.查看版本

ssh -V
OpenSSH, OpenSSL 1.1.1g  21 Apr 2020
原文地址:https://www.cnblogs.com/laod/p/14283399.html