不盲目跟别人。源码升级openssh

为了应付等保,本人借助vmware,测试升级openssh,数不清次数了,总结以下内容

CentOSopenssl 1.0.2*openssl 1.1.1*openssh 8.*openssh 9.*
5.*srcsrcsrc
6.*srcsrcsrc
7.*srcsrcsrc
8.*dnf updatesrcsrc

编译环境

yum install -y make gcc

telnet

1.1. centos5, centos6

yum install -y xinetd
vim /etc/xinetd.d/telnet

disable yes -> no

chkconfig xinetd on   ;\
service xinetd restart

1.2. centos7, centos8

yum install -y telnet*
systemctl enable telnet.socket;\
systemctl start  telnet.socket

2-1. 允许root登录,否则要登录其他账号再su到root

mv /etc/securetty /etc/securetty.org

PAM

如果源码安装了,就不用这一步,但是我不会源码装pam

yum install -y pam-devel

zlib

zlib很久没更新了,后面 openssh* config时候要找zlib.h

  1. 不源码
yum install -y zlib-devel
  1. 源码。要把源码安装后的动态库load进内存,才能找到zlib.h
    官网:http://www.zlib.net
    最新:http://www.zlib.net/zlib-1.2.11.tar.gz

README中并没有要求单独执行"make"

To compile all files and run the test program, follow the instructions given at
the top of Makefile.in. In short “./configure; make test”, and if that goes
well, “make install” should work for most flavors of Unix.

默认位置

tar xzf zlib-1.2.12.tar.gz ;\
cd zlib-1.2.12             ;\
./configure                ;\
make install

把动态库load进内存

echo '/usr/local/lib' > /etc/ld.so.conf.d/usr_local_lib.conf;\
ldconfig

load进内存后,rhel5的gnome桌面就完蛋啦~

不默认位置。prefix=/usr/local/zlib

./configure --prefix=/usr/local/zlib ;\
make install 

openssl 通过–with-zlib-lib=/usr/local/zlib/lib --with-zlib-include=/usr/local/zlib/include 通过编译
openssh 通过–with-zlib=/usr/local/zlib 完成编译

openssl

官网:https://www.openssl.org/
1.0当前最新:https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
1.1当前最新:https://www.openssl.org/source/openssl-1.1.1n.tar.gz

在openssh/INSTALL文件中有说明支持的openssl版本

  • OpenSSL (https://www.openssl.org) with any of the following versions:
    1.0.x >= 1.0.1 or 1.1.0 >= 1.1.0g or any 1.1.1
openssl version
  1. 系统原版本如果1.0,操作系统centos/rhel 5 可以源码装最新1.0

我最重要的生产环境是RHEL5.8 x390,用 CentOS 5.11 x86_64测试升级,openssl-1.1.0g在./config阶段已经报错,要求perl 5.10(CentOS 5.11 Final: Perl 5.8.8),及不支持系统。以下为报错信息

Operating system: x86_64-whatever-linux2
Perl v5.10.0 required–this is only v5.8.8, stopped at ./Configure line 12.
BEGIN failed–compilation aborted at ./Configure line 12.
Perl v5.10.0 required–this is only v5.8.8, stopped at ./Configure line 12.
BEGIN failed–compilation aborted at ./Configure line 12.
This system (linux-x86_64) is not supported. See file INSTALL for details.

  1. 系统原版本如果1.0,操作系统centos/rhel 6.* ~ 8.0,可以源码装最新1.1
  2. 系统原版本如果1.1(centos/rhel 8.1开始),不要装源码(准确点说不要把源码安装后的环境load进系统),装了重启就进不去了

  1. openssl-1.0.2*
tar xf openssl-1.0.2u.tar.gz; \
cd openssl-1.0.2u; \
./config shared; \
make; \
make install
  1. openssl-1.1.1*
tar xf openssl-1.1.1n.tar.gz; \
cd openssl-1.1.1n; \
./config; \
make; \
make install

网上其他教程里看到有人./config shared zlib-dynamic
openssh INSTALL里说了添加 -fPIC
到底要不要 shared?zib-dyn?-fPIC?

rhel 5.6 + openssl 1.0.2u 测试:
zlib-dyn 让openssl执行文件和libcrypto.a库大了一点,但是目录结构没变
shared 除了上面两个尺寸,lib下真正增加了libcrypto, libssl 一系列动态库
所以我觉得 <要>shared, <不要>zlib-dynamic
-fPIC 是默认参数,不用手动添加

centos 6.10 / centos.7.6.1810 + openssl 1.1.1k 测试
shared 有和没有安装过程无异,安装后 ldd 命令查询依赖关系无异
zlib-dyn 编译过程部分gcc命令多了“-DZLIB -DZLIB_SHARED”参数,安装完后openssl执行文件、libcrypto.a和libcrypto.so.1.1库都大一点,目录结构没有不同,ldd 查询依赖关系也没不同
所以我觉得 <不用>shared,<不用>zlib-dynamic

  1. 找到动态库位置,load进内存
    centos5,6
    动态库(libcrypto.a, libssl.a)在默认安装目录的lib下/usr/local/ssl/lib
echo '/usr/local/ssl/lib' > /etc/ld.so.conf.d/openssl.conf; \
ldconfig

centos7
动态库在 /usr/local/lib64 或者 /usr/local/lib下
如果存在/usr/local/lib64,动态库会放在这个目录,否则,动态库放在/usr/local/lib。
使用 make uninstall卸载,如果清除完动态库后目录空,会把该目录也删除了
例如:centos7安装完后默认存在/usr/local/lib64的空目录,首次源码安装openssl,动态库会放这里。如果后来用make uninstall删除,lib64会跟着删除,下次./config时候,动态库就不会放lib64而放lib

echo '/usr/local/lib64' > /etc/ld.so.conf.d/usr_local_lib64.conf; \
ldconfig

openssh

官网:http://www.openssh.com/
当前最新版:https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/openssh-7.9.tar.gz
解压

tar xf openssh-9.0p1.tar.gz
cd openssh-9*

默认位置(/usr/local),但是配置文件仍然设置在常见位置(/etc/ssh)。

之前学别人添加了 --with-md5-passwords,在最新9在config阶段已经提示不识别了,所以去掉

./configure --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local;\
make

移开原始配置目录

mv /etc/ssh /etc/ssh_$sshver

安装

make install

配置sshd_config

vim /etc/ssh/sshd_config

让root可以登录
32行:PermitRootLogin yes
让secureCRT可以通过Xmanager被动模式启动图形界面
90行:X11Forwarding yes

之前我会修改服务配置文件,指定到新执行文件位置,后来装oracle时候发现它会在固定位置找执行文件,所以最后还是乖乖替换执行文件吧
编辑脚本里2个执行文件位置
vim /etc/init.d/sshd
25行:SSHD=/usr/local/sbin/sshd
41行:/usr/local/bin/ssh-keygen -A

首次源码更新,备份原始执行文件。因为创建了软链接,以后更新不用备份快捷方式了

mv /usr/bin/scp             /usr/bin/scp_$sshver         ;\
mv /usr/bin/sftp            /usr/bin/sftp_$sshver        ;\
mv /usr/bin/ssh             /usr/bin/ssh_$sshver         ;\
mv /usr/bin/ssh-add         /usr/bin/ssh-add_$sshver     ;\
mv /usr/bin/ssh-agent       /usr/bin/ssh-agent_$sshver   ;\
mv /usr/bin/ssh-keygen      /usr/bin/ssh-keygen_$sshver  ;\
mv /usr/bin/ssh-keyscan     /usr/bin/ssh-keyscan_$sshver ;\
mv /usr/sbin/sshd           /usr/sbin/sshd_$sshver       ;\

ln -s /usr/local/bin/scp          /usr/bin/scp           ;\
ln -s /usr/local/bin/sftp         /usr/bin/sftp          ;\
ln -s /usr/local/bin/ssh          /usr/bin/ssh           ;\
ln -s /usr/local/bin/ssh-add      /usr/bin/ssh-add       ;\
ln -s /usr/local/bin/ssh-agent    /usr/bin/ssh-agent     ;\
ln -s /usr/local/bin/ssh-keygen   /usr/bin/ssh-keygen    ;\
ln -s /usr/local/bin/ssh-keyscan  /usr/bin/ssh-keyscan   ;\
ln -s /usr/local/sbin/sshd        /usr/sbin/sshd         

ssh-copy-id 好像有点特别,make install后没在bin目录,在contrib里,没有x属性,所以单独处理:每次备份,复制,授权

mv /usr/bin/ssh-copy-id     /usr/bin/ssh-copy-id_$sshver ;\
cp contrib/ssh-copy-id      /usr/bin/ssh-copy-id         ;\
chmod +x /usr/bin/ssh-copy-id
替换service启动脚本
centos7,8刚开始没有/etc/init.d/sshd这个启动脚本,而是/usr/lib/systemd/system里的东西
systemctl disable sshd;\
systemctl stop    sshd;\
mv /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.service_$sshver;\
mv /usr/lib/systemd/system/sshd.socket  /usr/lib/systemd/system/sshd.socket_$sshver
mv /etc/init.d/sshd /etc/init.d/sshd_$sshver    ;\
cp contrib/redhat/sshd.init /etc/init.d/sshd    ;\
systemctl start  sshd;\
systemctl enable sshd;\
systemctl status sshd
centos5,6
chkconfig sshd off                              ;\
service sshd stop                               ;\
mv /etc/init.d/sshd /etc/init.d/sshd_$sshver    ;\
cp contrib/redhat/sshd.init /etc/init.d/sshd    ;\
service sshd start                              ;\
chkconfig sshd on                               ;\
service sshd status    

尝试登录一次,产生一条selinux信息

ssh localhost
@@@@@ /bin/bash: Permission denied
@@@@@ Connection to localhost closed.

mkdir /opt/selinux; cd /opt/selinux ;\
ausearch -c 'sshd' --raw | audit2allow -M my-sshd; semodule -X 300 -i my-sshd.pp
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值