centos与ubuntu升级openssh详细操作

安装时发现各种报错,各种缺少依赖,以下是自己安装时碰到的问题。可做参考

因为Openssh MaxAuthTries限制绕过漏洞问题,升级

1. 关闭selinux(若ubuntu没有,可以不设置)
vim /etc/sysconfig/selinux
修改 SELINUX=disabled
(原始enforcing)

一 前期准备
1.1 依赖安装

1、 Zlib1.1.4或1.2.1.2或更高版本
       本次使用  zlib-1.2.11    http://www.zlib.net/
       安装步骤:
       (1)上传zlib源码到服务器的/usr/local/src,并解压
       (2)切换到zlib目录下,编译zlib
                                ./configure    --prefix=/usr/local/zlib
                                    make
                                    make  install
        (3)更新动态链接库数据
                  echo "/usr/local/zlib/lib" >> /etc/ld.so.conf 
                  ldconfig -v
   2、 OpenSSL版本:目前OpenSSH8.0p1不支持OpenSSL1.1.x以上。否则编译的时候会报错。
       本次使用  OpenSSL1.1.0k     https://www.openssl.org/source/ 
       安装步骤:
       (1)上传zlib源码到服务器的/usr/local/src,并解压
       (2)编译安装
                ./config  shared && make && make install
                创建软链接,根据自己情况:
                (centos)
                 ln -s /usr/lib64/libcrypto.so.1.0.0  /usr/lib64/libcrypto.so.10
                 ln -s /usr/lib64/libssl.so.1.0.0  /usr/lib64/libssl.so.10
                 (ubuntu)
                 ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl 
                 ln -s /usr/local/ssl/include/openssl /usr/include/openssl 
        (3)将openssl 的lib 库添加到系统 
                  echo "/usr/local/ssl/lib" > /etc/ld.so.conf.d/openssl.conf
                  使新添加的lib 被系统找到
                  ldconfig  
        (4)验证版本信息:
                 openssl version -a
3、 gcc:因为编译需要gcc,根据提示安装缺少的
4、 openssl-devel:编译时需要,根据提示安装缺少的


二、安装openssh
源码地址:http://www.openssh.com/portable.html
1.备份sshd_config配置文件(方便后期使用或者方便升级失败使用)
  (centos)
    /etc/ssh
  (ubuntu)
    /etc/ssh
    /etc/init.d/ssh   
    
2.解压安装
        tar -zxvf openssh-7.9p1.tar.gz
        cd openssh-7.9p1

        以前编译,使用一种及可,我是碰到openssl  version library  not  found,因此指定了一下ssl刚才安装的位置
        ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-privsep-path=/var/lib/sshd
        ./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/ssl --with-md5-passwords --with-zlib=/usr/local/zlib
        ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-ssl-dir=/usr/local--with-privsep-path=/var/lib/sshd
        make
   如果报错
        ① configure: error: no acceptable C compiler found in $PATH
        问题解决
        yum install gcc
        ② configure: error: * zlib.h missing - please install first or check config.log *
        问题解决
        yum install openssl openssl-devel -y 安装相关依赖包
        ---------------------------------报错-------------------------------------------
# 报错  checking whether OpenSSL's PRNG is internally seeded... yes
#       configure: error: PAM headers not found
# 解决:ubuntu: apt-get install libpam0g-dev   centos: yum -y install pam-devel
--------------------------------------------------------------------------------
make 
make install 
---------------------------------报错-------------------------------------------------------------------
# 报错: Privilege separation user sshd does not exist
vim /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 
# 注册名:口令:用户标识号:组标识号:用户名:用户主目录:命令解释程序
# /etc/passwd文件是Linux/UNIX安全的关键文件之一.该文件用于用户登录时校验 用户的口令,当然应当仅对root可写.
---------------------------------------------------------------------------------------------------------

        命令解释:
    --sysconfdir=/etc/ssh:这可以防止安装配置文件 /usr/etc。
    --with-md5-passwords:这使得可以使用MD5密码。
    --with-pam:此参数在构建中启用 Linux-PAM支持。
--with-xauth=/usr/bin/xauth:为X身份验证设置xauth二进制文件的默认位置。如果将xauth安装到其他路径,请更改位置。这也可以sshd_config使用XAuthLocation关键字进行控制。如果已安装Xorg,则可以省略此开关。
--with-kerberos5=/usr:此选项用于在构建中包含Kerberos 5支持。
--with-libedit:此选项为sftp启用行编辑和历史记录功能。
3、修改相应文件权限
        chmod 600 /etc/ssh/ssh_host_rsa_key
        chmod 600 /etc/ssh/ssh_host_ecdsa_key
        chmod 600 /etc/ssh/ssh_host_ed25519_key
4、安装
    make install
5.根据自身需求改写配置,也可用原备份文件覆盖
注意:默认是22端口,但是不能root直接登录。如果想直接使用root登录执行以下命令
(centos)/etc/sshd_config    PermitRootLogin yes
6.开机自启动
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
chkconfig --add sshd                  (chkconfig命令,ubuntu没有,因此没有做一下操作)
chkconfig sshd on
chkconfig --list sshd
systemctl restart sshd
7.验证操作
ssh -V
8.重启ssh服务
    service sshd restart(重启超时失败时,使用sshd -t查看错误解决)
    会发现连接不上,这个问题是selinux修改要生效需要重启机器
    重启机器后连接成功
    升级完成

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值