Centos7 openssh7.4p1升级openssh8.8p1

简单科普:ssh和sshd的区别,ssh是针对客户端的涉及的配置文件是ssh_config配置文件,sshd是针对服务端的涉及的配置文件时sshd_config配置文件。

# 1、查看当前ssh版本
ssh -V
# 2、查看ssh和sshd的安装路径,方便升级后指定二进制文件的存放位置
find / -name 'ssh'
find / -name 'sshd'
# 3、安装升级依赖
yum -y install gcc gcc-c++ kernel-devel
# 4、下载源码包、个人习惯存放路径/data/software
cd /data/software
wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.8p1.tar.gz 
# 5、解压源码包
tar xf openssh-8.8p1.tar.gz
tar xf openssl-1.1.1h.tar.gz
tar xf zlib-1.2.11.tar.gz
# 6、编译安装zlib 【prefix=/usr/local/zlib 方便自己管理(因为每一个应用的构建物,他的东西,都放在一个目录里,要删,直接删这个目录就行)】
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
# 7、编译 -j <服务器cpu数量>  写多少就是用几个内核进行编译,会快一些
make -j 2
# make install 开始进行安装,执行完成后 zlib会出现在/usr/local/ 这个目录下
make install
# 8、安装 openssl
cd openssl-1.1.1h/
./config --prefix=/usr/local/ssl -d shared
make -j 2
make install
# 9、将ssl动态库路径写入到/etc/ld.so.conf配置文件中,该.conf配置文件为加载so库的路径配置文件
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
# 查看加载动态库
ldconfig -v
# 10、安装openssh-8.8p1
# 备份原来的的配置文件
mv /etc/ssh /etc/ssh.bak
mkdir -p /etc/ssh
cd /data/software/openssh-8.8p1/
./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib
# 如果提示
# configure: error: Your OpenSSL headers do not match your
# 	library. Check config.log for details.
# 	If you are sure your installation is consistent, you can disable the check
# 	by running "./configure --without-openssl-header-check".
# 	Also see contrib/findssl.sh for help identifying header/library mismatches.
# 尝试增加--without-openssl-header-check
# ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/zlib --without-openssl-header-check
make -j 2
make install
# 11、修改sshd_config文件,将配置写入到sshd_config
# 必须添加X11UseLocalhost no 和 XAuthLocation /usr/bin/xauth 这两项,否则X11转发异常
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

# 备份 /etc/ssh 原有文件,并将新的配置复制到指定目录;注意自己的安装路径
mv /usr/sbin/sshd /usr/sbin/sshd.bak
cp -rf /usr/local/openssh/sbin/sshd /usr/sbin/sshd
mv /usr/bin/ssh /usr/bin/ssh.bak
cp -rf /usr/local/openssh/bin/ssh /usr/bin/ssh 
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp -rf /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

# ssh -V 查看安装后的版本
[root@i-b125a406 openssh-8.8p1]# ssh -V
OpenSSH_8.8p1, OpenSSL 1.1.1h  22 Sep 2020
# 启动sshd
systemctl start sshd
# 解决错误--start 如果无法启动ssh 建议先用 sshd -t 检查有无错误
# <1>、先停止sshd服务 
systemctl stop sshd
# <2>、将systemctl原服务删除
rm -rf /lib/systemd/system/sshd.service 
# <3>、使用安装包里自带的sshd.init,复制到/etc/init.d/sshd,然后进行重启
systemctl daemon-reload
cp /data/software/openssh-8.8p1/contrib/redhat/sshd.init /etc/init.d/sshd
/etc/init.d/sshd restart
# 查看状态
systemctl status sshd
# 使用 /etc/init.d/sshd restart 进行重启
/etc/init.d/sshd restart
# 解决错误--end
# 12、添加开机启动项
chkconfig --add  sshd
# 查看启动配置
chkconfig --list sshd
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值