openssh 更新

发布 : 2023-03-17 分类 : openssh 浏览 :

openssh 更新

Windows 和 Linus 更新

1. Windows 更新

OpenSSH 是作为系统内自带的应用,是不能更新的,但是可以配置新版本的 OpenSSH 达到更新目的
下载 OpenSSH 的发行版本,并配置到环境变量,这样 Powershell 或者 Windows Terminal 就会自动调取用户配置好的 OpenSSH 版本,而不影响系统自带的 OpenSSH。

打开 Powershell 或者 Windows Terminal 输入 ssh -V 查看版本

https://github.com/PowerShell/Win32-OpenSSH/releases​github.com/PowerShell/Win32-OpenSSH/releases 下载 OpenSSH-Win64.zip

解压后复制路径配置到环境变量即可

Path 追加解压后的地址并移动到系统 OpenSSH 的上方:
F:\program\OpenSSH-Win64\
C:\WINDOWS\System32\OpenSSH\

重新打开 Windows Terminal 或 Powershell 即可查看版本是否升级了 ssh -V

2. Linux 更新

再更新前如果是远程机器使用ssh登陆 那就需要做个冗余备份操作 可以是镜像 也可以是安装telnet 防止ssh更新不成功导致不能登陆系统

telnet的安装请看 https://blog.zhouinfo.site/2022/11/22/telnet/

安装后测试能使用telnet登陆后再进行更新

前置条件 需要有gcc编译环境
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel

需要 openssl zlib 版本匹配才能编译 openssh 所以需要先编译 openssl zlib

编译 zlib

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#zlib
cd /usr/local/src
wget http://www.zlib.net/zlib-1.2.13.tar.gz
tar zxvf zlib-1.2.13.tar.gz
cd zlib-1.2.13/
./configure --prefix=/usr/local/zlib
make && make install

find / -name zlib.pc
cat /usr/local/zlib/lib/pkgconfig/zlib.pc
#prefix=/usr/local/zlib
#exec_prefix=${prefix}
#libdir=${exec_prefix}/lib
#sharedlibdir=${libdir}
#includedir=${prefix}/include

#Name: zlib
#Description: zlib compression library
#Version: 1.2.13

#Requires:
#Libs: -L${libdir} -L${sharedlibdir} -lz
#Cflags: -I${includedir}

cat /usr/lib64/pkgconfig/zlib.pc
#prefix=/usr
#exec_prefix=${prefix}
#libdir=/usr/lib64
#sharedlibdir=${libdir}
#includedir=/usr/include

#Name: zlib
#Description: zlib compression library
#Version: 1.2.7

#Requires:
#Libs: -L${libdir} -L${sharedlibdir} -lz
#Cflags: -I${includedir}


curl -V
#curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0
#Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
#Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets

ssh -V
#OpenSSH_9.1p1, OpenSSL 1.1.1m 14 Dec 2021

#备份
cp /lib64/libz.so.1.2.7 /lib64/libz.so.1.2.7.bak
make clean
ln -snf /lib64/libz.so.1.2.7.bak /lib64/libz.so.1

开始编译 openssl

1
2
3
4
5
6
7
8
9
10
11
12
#openssl
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz --no-check-certificate
openssl -V
openssl version
tar -zxvf openssl-1.1.1m.tar.gz
cd openssl-1.1.1m/
./config --prefix=/usr/local/ssl -d shared
make && make install
echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
ldconfig -v

开始编译 openssh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
cd /usr/local/src
#最新源码 `https://www.openssh.com/releasenotes.html`
#wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz
#wget https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz?spm=a2c6h.25603864.0.0.686840adET0MEE --no-check-certificate
#wget https://mirror.leaseweb.com/pub/OpenBSD/OpenSSH/portable/openssh-9.1p1.tar.gz --no-check-certificate

tar zxvf openssh-9.1p1.tar.gz
cd openssh-9.1p1/
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install

echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config

mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
mv /usr/sbin/sshd /usr/sbin/sshd.bak
mv /usr/bin/ssh /usr/bin/ssh.bak
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
mv /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak

cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
systemctl daemon-reload
service sshd restart

vim /etc/ssh/sshd_config
vim /etc/systemd/system/multi-user.target.wants/sshd.service
vim /etc/systemd/system/multi-user.target.wants/sshd.service
systemctl daemon-reload
service sshd restart

ssh -V

本文作者 : zhouinfo
原文链接 : http://blog.zhouinfo.site/2023/03/17/openssh-%E6%9B%B4%E6%96%B0/
版权声明 : 本博客所有文章除特别声明外,均采用 CC Apache License 2.0 许可协议。转载请注明出处!
留下足迹