当前位置:   article > 正文

CentOS7以上更新OpenSSH、OpenSSL_centos服务器openssl和和openssh升级

centos服务器openssl和和openssh升级

目前最新的OpenSSH是openssh9.1p1,至于为什么不升级到最新版本,是因为openssh8.9版本以上不支持key转发了。详情可以看一看这个文章:
https://editor.csdn.net/md/?articleId=128041801

CentOS7以上版本一般不需要更新OpenSSl就可以成功更新Openssh,大家可以根据自己的需求,也可以不更新OpenSSL直接安装OpenSSH。
安装Perl、OpenSSL

1. 安装编译需要的环境

yum -y install gcc gcc-c++ glibc make zlib zlib-devel pam-devel openssl-devel rpm-build
  • 1

2. 下载安装Perl

wget https://www.cpan.org/src/5.0/perl-5.36.0.tar.gz
tar zxf perl-5.36.0.tar.gz 
cd perl-5.36.0 
./Configure -des -Dprefix=/usr/local/perl 
make && echo $? 
make install 
mv /usr/bin/perl /usr/bin/perl.bak 
ln -s /usr/local/perl/bin/perl /usr/bin/perl 
perl -v 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

3. 下载、解压、编译安装OpenSSL

wget https://www.openssl.org/source/openssl-3.0.7.tar.gz
tar zxf openssl-3.0.7.tar.gz
cd openssl-3.0.7
./config --prefix=/usr/local/ssl shared zlib
make && make install 

mv /usr/bin/openssl /usr/bin/openssl.bak 
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl 
echo "/usr/local/ssl/lib64">> //etc/ld.so.conf.d/ssl.conf
/sbin/ldconfig 
openssl version 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

安装OpenSSH**********注意,一定要有备用的连接方式,安装过程很可能ssh掉线,防止无法远程连接到服务器。telnet是个很好的选择。我的是虚拟机,有VNC,所以没有配置telnet***********

1. 安装编译需要的环境

yum -y install gcc gcc-c++ glibc make zlib zlib-devel pam-devel openssl-devel rpm-build
  • 1

2. 备份旧版本的配置文件、卸载旧版本openssh,我这旧版本是之前rpm安装的,源码安装的可以自行寻找安装位置。

mv -f /etc/ssh /etc/ssh.bak
for i in `rpm -qa |grep openssh-`; do rpm -e --nodeps $i; done
  • 1
  • 2

3. 下载并安装

wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.8p1.tar.gz
tar zxvf openssh-8.8p1.tar.gz
  • 1
  • 2

如果编译安装了OpenSSL,就要更改ssh的编译参数,需要添加 --without-openssl-header-check --with-ssl-dir=/usr/local/ssl 这个/usr/loca/ssl是你安装SSL的位置,你安装到了那就写哪

cd openssh-8.8p1
  • 1

#根据情况选一个运行
#不指定SSL位置

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords 
  • 1

#指定SSL位置

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers --without-openssl-header-check --with-ssl-dir=/usr/local/ssl
  • 1

编译后安装

make
echo $?
make install
  • 1
  • 2
  • 3

4. 创建软连接,备份旧的启动文件

ln -sf /usr/local/openssh/bin/* /usr/bin
ln -sf /usr/local/openssh/sbin/sshd /usr/sbin
cd /usr/lib/systemd/system/
mv sshd.service{,.bak}
mv sshd.keygen.service{,.bak}
mv sshd.socket{,.bak}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

5. 更改sshd配置文件
我这里是要求key登陆的,大家可以根据自己的需求修改下面的参数。
PermitRootLogin yes #是否允许root登陆
PasswordAuthentication no #是否允许密码登陆
PubkeyAuthentication yes #是否允许密钥登陆
X11Forwarding yes #是否允许X11转发,用不到的可以不开这个,默认是关闭状态

echo -e "PermitRootLogin yes\nPasswordAuthentication no\nPubkeyAuthentication yes\nX11Forwarding yes">>/etc/ssh/sshd_config
  • 1

6. 新建启动文件
写入sshd-keygen.service

cat << __EOF__ >> /usr/lib/systemd/system/sshd-keygen.service
[Unit]
Description=OpenSSH Server Key Generation
Conditionsshd_service_FILENotEmpty=|!/etc/ssh/ssh_host_rsa_key
Conditionsshd_service_FILENotEmpty=|!/etc/ssh/ssh_host_ecdsa_key
Conditionsshd_service_FILENotEmpty=|!/etc/ssh/ssh_host_ed25519_key
PartOf=sshd.service sshd.socket

[Service]
ExecStart=/usr/sbin/sshd-keygen
Type=oneshot
RemainAfterExit=yes
__EOF__
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

写入sshd.socket

cat << __EOF1__ >> /usr/lib/systemd/system/sshd.socket
[Unit]
Description=OpenSSH Server Socket
Documentation=man:sshd(8) man:sshd_config(5)
Conflicts=sshd.service

[Socket]
ListenStream=22
Accept=yes

[Install]
WantedBy=sockets.target
__EOF1__
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

写入sshd.service

cat << __EOF2__ >> /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
# 这里的type只能是simple,notify会获取不到satus
Type=simple
Environmentsshd_service_FILE=/etc/sysconfig/sshd
#如果手动复制文办请把转义符"\"去掉
ExecStart=/usr/sbin/sshd -D \$OPTIONS
#如果手动复制文办请把转义符"\"去掉
ExecReload=/bin/kill -HUP \$MAINPID 
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
__EOF2__
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

7. 重启服务

systemctl daemon-reload
systemctl enable --now sshd
systemctl restart sshd
systemctl status sshd
  • 1
  • 2
  • 3
  • 4

8. 验证

ssh –V
sshd -V
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/285754
推荐阅读
相关标签
  

闽ICP备14008679号