记录一次Anolis OS8.9 升级openssh9.9全过程

记录一次Anolis OS8.9 升级openssh9.9全过程

做这个的背景是因为一次漏扫,安恒的设备扫出来了一个高危,看了一下是因为服务器的Openssh版本低的原因,原来的系统9.0,2021年的版本,现在要求最低9.8.没办法,升级吧,

不同的地方

踩了一些坑,比如说Anolis OS和Centos还有有一些不同的,最大的不同点在于龙蜥系统的服务需要手动添加到系统中去,其他的一些权限的问题还好说。

开始吧
##准备工作

下载源文件
下载openssl(3.0.16)
https://openssl-library.org/source/

请添加图片描述
下载Openssh9.9-p2
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/

在这里插入图片描述
放到自己机器上备用

##安装依赖包
包括gcc pam zlib perl等

// An highlighted block
yum  -y install pam-devel.x86_64 perl-devel zlib zlib-devel perl-IPC-Cmd perl-Data-Dumper gcc

在这里插入图片描述
##安装openssl
上传openssl和openssh到 opt目录下(用rz命令)
rz
比较好的是Anolis OS 如果没有安装会自动检测安装
在这里插入图片描述
切换到opt 目录
上传两个文件并解压
在这里插入图片描述

// An highlighted block
tar -zvxf openssl-3.0.16.tar.gz 
tar -zvxf openssh-9.9p2.tar.gz

解压后:
在这里插入图片描述
进入目录:
cd openssl-3.0.16

编译并输出到 /usr/local/openssl 目录下:

./config --prefix=/usr/local/openssl

安装:
make && make install
在这里插入图片描述
时间会有点长,稍等一会

###删除老版本openssl
备份老版本openssl

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

建立软连接

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib64/libssl.so.3 /usr/lib64/libssl.so.3
ln -s /usr/local/openssl/lib64/libcrypto.so.3 /usr/lib64/libcrypto.so.3

更新动态连接库使新openssl生效

echo "/usr/local/openssl/lib64" >> /etc/ld.so.conf
ldconfig

在这里插入图片描述

##安装openssh9.9 p2

备份原openssh文件夹

cp -r /etc/ssh /etc/ssh.old

拷贝原配置文件备用

cp /etc/ssh/sshd_config  /opt/sshd_config.bak
cp /etc/pam.d/sshd  /opt/sshd.bak

查询并卸载原iopenssh
在这里插入图片描述
依次卸载

rpm -e --nodeps openssh-8.0p1-20.0.1.an8.x86_64
rpm -e --nodeps openssh-server-8.0p1-20.0.1.an8.x86_64
rpm -e --nodeps openssh-clients-8.0p1-20.0.1.an8.x86_64

验证
在这里插入图片描述

切换目录
cd /opt/openssh-9.9p2
验证,输出文件

./configure --prefix=/usr/local/openssh9.9 --exec-prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-zlib --with-ssl-dir=/usr/local/openssl --without-hardening  --without-openssl-header-check

在这里插入图片描述
到这里说明验证成功
编译安装

make && make install

需要赋权
在这里插入图片描述
赋权

chmod 600 /etc/ssh/ssh_host_*_key

验证

在这里插入图片描述
如果不成功重新编译

在这里插入图片描述
拷贝

cp -a /opt/openssh-9.9p2/contrib/redhat/sshd.init /etc/init.d/sshd
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

回考配置文件(当然也可以手动改新生成的)
在这里插入图片描述
手动修改的就不用了复制了

echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
echo 'X11Forwarding yes' >> /etc/ssh/sshd_config  #

给当前用户设置访问权限(root)
chmod u+x /etc/init.d/sshd
新建sshd.servcie
vim /etc/sysconfig/sshd
添加如下内容

'# Configuration file for the sshd service.
'# The server keys are automatically generated if they are missing.
'# To change the automatic creation uncomment and change the appropriate
'# line. Accepted key types are: DSA RSA ECDSA ED25519.
'# The default is “RSA ECDSA ED25519”
'# AUTOCREATE_SERVER_KEYS=“”
'# AUTOCREATE_SERVER_KEYS=“RSA ECDSA ED25519”
'# Do not change this option unless you have hardware random
'# generator and you REALLY know what you are doing
SSH_USE_STRONG_RNG=0
'# SSH_USE_STRONG_RNG=1

继续新建
vi /usr/lib/systemd/system/sshd.service

[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target
[Service]
Type=notify
EnvironmentFile=-/etc/crypto-policies/back-ends/opensshserver.config
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS -oCiphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc -oMACs=hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ecdsa-sha2-nistp384,rsa-sha2-512
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target

授权
chmod 600 /etc/ssh/ssh_host_rsa_key
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chmod 600 /etc/ssh/ssh_host_ed25519_key

重新加载服务

systemctl daemon-reload

重启服务

systemctl restart sshd

重新设置开机启动

systemctl enable sshd.service

登录验证
在这里插入图片描述
配置文件可以根据自己需要编辑

踩坑的地方:
加密方式选择不能选择: $CRYPTO_POLICY所有的加密方式,有的加密方式会有冲突。
编译的地方会有问题,会出现编译成功

参考链接:
https://blog.csdn.net/zhang546030919/article/details/140550933
https://blog.csdn.net/hooimongyi/article/details/143230056

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值