• 编译CentOS6.10系统的OpenSSHV9.4rpm安装包


     目前OpenSSH版本已至9.4,其作为操作系统底层管理平台软件,需要保持更新以免遭受安全攻击,编译生成rpm包是生产环境中批量升级的最佳途径。编译软件包时与当前的运行环境有较大关系,请注意本安装包系在CentOS6.10原生系统纯净系统下编译完成的。

    一、准备编译环境:

     1、发布一台虚拟机,最小化安装CentOS6.10,查看系统信息如下:

    1. [root@localhost ~]# cat /etc/redhat-release
    2. CentOS release 6.10 (Final)

     2、查看系统所带openssl的版本信息:

    1. [root@localhost ~]# rpm -qa|grep openssh
    2. openssh-5.3p1-123.el6_9.x86_64
    3. openssh-server-5.3p1-123.el6_9.x86_64
    4. [root@localhost ~]# rpm -qa|grep openssl
    5. openssl-1.0.1e-57.el6.x86_64

     3、修改系统源为阿里源:

    1. [root@localhost ~]# cd /etc/yum.repos.d/
    2. [root@localhost yum.repos.d]# rm CentOS-* -rf
    3. [root@localhost yum.repos.d]# vi http.repo
    4. [root@localhost yum.repos.d]# cat http.repo
    5. [os]
    6. name=os
    7. baseurl=https://mirrors.aliyun.com/centos-vault/6.10/os/x86_64/
    8. gpgcheck=0
    9. enabled=1
    10. [root@localhost yum.repos.d]# cd ~
    11. [root@localhost ~]# yum repolist
    12. 已加载插件:fastestmirror
    13. Determining fastest mirrors
    14. os | 3.7 kB 00:00
    15. os/primary_db | 4.7 MB 00:04
    16. 仓库标识 仓库名称 状态
    17. os os 6,713
    18. repolist: 6,713

     4、准备相关目录及工具

    1. [root@localhost ~]# cd ~
    2. [root@localhost ~]# mkdir -p rpmbuild/{SOURCES,SPECS}
    3. [root@localhost ~]# yum install wget tree -y
    4. 已加载插件:fastestmirror
    5. 设置安装进程
    6. Loading mirror speeds from cached hostfile
    7. 解决依赖关系
    8. --> 执行事务检查
    9. ---> Package tree.x86_64 0:1.5.3-3.el6 will be 安装
    10. ---> Package wget.x86_64 0:1.12-10.el6 will be 安装
    11. --> 完成依赖关系计算
    12. 依赖关系解决
    13. =========================================================================================================================================================
    14. 软件包 架构 版本 仓库 大小
    15. =========================================================================================================================================================
    16. 正在安装:
    17. tree x86_64 1.5.3-3.el6 os 36 k
    18. wget x86_64 1.12-10.el6 os 484 k
    19. 事务概要
    20. =========================================================================================================================================================
    21. Install 2 Package(s)
    22. 总下载量:520 k
    23. Installed size: 1.9 M
    24. 下载软件包:
    25. (1/2): tree-1.5.3-3.el6.x86_64.rpm | 36 kB 00:00
    26. (2/2): wget-1.12-10.el6.x86_64.rpm | 484 kB 00:00
    27. ---------------------------------------------------------------------------------------------------------------------------------------------------------
    28. 总计 799 kB/s | 520 kB 00:00
    29. 运行 rpm_check_debug
    30. 执行事务测试
    31. 事务测试成功
    32. 执行事务
    33. 正在安装 : tree-1.5.3-3.el6.x86_64 1/2
    34. 正在安装 : wget-1.12-10.el6.x86_64 2/2
    35. Verifying : wget-1.12-10.el6.x86_64 1/2
    36. Verifying : tree-1.5.3-3.el6.x86_64 2/2
    37. 已安装:
    38. tree.x86_64 0:1.5.3-3.el6 wget.x86_64 0:1.12-10.el6
    39. 完毕!

    5、 准备源文件

    1. [root@localhost ~]# cd rpmbuild/SOURCES/
    2. [root@localhost SOURCES]# wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.4p1.tar.gz --no-check-certificate
    3. ...
    4. 2023-09-05 18:33:37 (69.2 KB/s) - 已保存 “openssh-9.4p1.tar.gz” [1845094/1845094])
    5. [root@localhost SOURCES]# wget https://src.fedoraproject.org/repo/pkgs/openssh/x11-ssh-askpass-1.2.4.1.tar.gz/8f2e41f3f7eaa8543a2440454637f3c3/x11-ssh-askpass-1.2.4.1.tar.gz
    6. ...
    7. 2023-09-05 18:41:14 (114 KB/s) - 已保存 “x11-ssh-askpass-1.2.4.1.tar.gz” [29229/29229])
    8. [root@localhost SOURCES]# wget https://www.openssl.org/source/openssl-1.1.1v.tar.gz --no-check-certificate
    9. ...
    10. 2023-09-06 21:56:18 (901 KB/s) - 已保存 “openssl-1.1.1v.tar.gz” [9893443/9893443])
    11. [root@localhost SOURCES]# vi sshd.pam.el6
    12. #%PAM-1.0
    13. auth required pam_sepermit.so
    14. auth include password-auth
    15. account required pam_nologin.so
    16. account include password-auth
    17. password include password-auth
    18. # pam_selinux.so close should be the first session rule
    19. session required pam_selinux.so close
    20. session required pam_loginuid.so
    21. # pam_selinux.so open should only be followed by sessions to be executed in the user context
    22. session required pam_selinux.so open env_params
    23. session optional pam_keyinit.so force revoke
    24. session include password-auth
    25. "sshd.pam.el6" [New] 13L, 575C written
    26. [root@localhost SOURCES]# cat sshd.pam.el6
    27. #%PAM-1.0
    28. auth required pam_sepermit.so
    29. auth include password-auth
    30. account required pam_nologin.so
    31. account include password-auth
    32. password include password-auth
    33. # pam_selinux.so close should be the first session rule
    34. session required pam_selinux.so close
    35. session required pam_loginuid.so
    36. # pam_selinux.so open should only be followed by sessions to be executed in the user context
    37. session required pam_selinux.so open env_params
    38. session optional pam_keyinit.so force revoke
    39. session include password-auth
    40. [root@localhost SOURCES]# ll
    41. 总用量 11504
    42. -rw-r--r--. 1 root root 1845094 8月 10 11:15 openssh-9.4p1.tar.gz
    43. -rw-r--r--. 1 root root 9893443 8月 1 22:09 openssl-1.1.1v.tar.gz
    44. -rw-r--r--. 1 root root 575 9月 6 19:38 sshd.pam.el6
    45. -rw-r--r--. 1 root root 29229 6月 26 2004 x11-ssh-askpass-1.2.4.1.tar.gz

    6、 安装编译工具

    1. [root@localhost SOURCES]# cd ../SPECS
    2. [root@localhost SPECS]# yum install rpm-build zlib-devel openssl-devel gcc perl-devel pam-devel -y
    3. ...
    4. 已安装:
    5. gcc.x86_64 0:4.4.7-23.el6 openssl-devel.x86_64 0:1.0.1e-57.el6 pam-devel.x86_64 0:1.1.1-24.el6 perl-devel.x86_64 4:5.10.1-144.el6
    6. rpm-build.x86_64 0:4.8.0-59.el6 zlib-devel.x86_64 0:1.2.3-29.el6
    7. 作为依赖被安装:
    8. cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-23.el6 db4-cxx.x86_64 0:4.7.25-22.el6
    9. db4-devel.x86_64 0:4.7.25-22.el6 elfutils.x86_64 0:0.164-2.el6 gdb.x86_64 0:7.2-92.el6
    10. gdbm-devel.x86_64 0:1.8.0-39.el6 glibc-devel.x86_64 0:2.12-1.212.el6 glibc-headers.x86_64 0:2.12-1.212.el6
    11. kernel-headers.x86_64 0:2.6.32-754.el6 keyutils-libs-devel.x86_64 0:1.4-5.el6 krb5-devel.x86_64 0:1.10.3-65.el6
    12. libcom_err-devel.x86_64 0:1.41.12-24.el6 libgomp.x86_64 0:4.4.7-23.el6 libkadm5.x86_64 0:1.10.3-65.el6
    13. libselinux-devel.x86_64 0:2.0.94-7.el6 libsepol-devel.x86_64 0:2.0.41-4.el6 mpfr.x86_64 0:2.4.1-6.el6
    14. patch.x86_64 0:2.6-8.el6_9 perl.x86_64 4:5.10.1-144.el6 perl-ExtUtils-MakeMaker.x86_64 0:6.55-144.el6
    15. perl-ExtUtils-ParseXS.x86_64 1:2.2003.0-144.el6 perl-Module-Pluggable.x86_64 1:3.90-144.el6 perl-Pod-Escapes.x86_64 1:1.04-144.el6
    16. perl-Pod-Simple.x86_64 1:3.13-144.el6 perl-Test-Harness.x86_64 0:3.17-144.el6 perl-libs.x86_64 4:5.10.1-144.el6
    17. perl-version.x86_64 3:0.77-144.el6 ppl.x86_64 0:0.10.2-11.el6 redhat-rpm-config.noarch 0:9.0.3-51.el6.centos
    18. unzip.x86_64 0:6.0-5.el6 xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6 xz-lzma-compat.x86_64 0:4.999.9-0.5.beta.20091007git.el6
    19. 完毕!

    7、 生成源spec文件

    1. [root@localhost SPECS]# vi openssh.spec
    2. [root@localhost SPECS]# cat openssh.spec
    3. %{?!opensslver: %global opensslver 1.1.1v}
    4. %{?!opensshver: %global opensshver 9.4p1}
    5. %define static_openssl 1
    6. # wheather to build openssl
    7. %global no_build_openssl 0
    8. #if defined openssl_dir, don't build it
    9. %{?openssl_dir:%global no_build_openssl 1}
    10. %global ver %{?opensshver}
    11. %global rel %{?opensshpkgrel}%{?dist}
    12. # OpenSSH privilege separation requires a user & group ID
    13. %global sshd_uid 74
    14. %global sshd_gid 74
    15. # Version of ssh-askpass
    16. %global aversion 1.2.4.1
    17. # Do we want to disable building of x11-askpass? (1=yes 0=no)
    18. %global no_x11_askpass 1
    19. # Do we want to disable building of gnome-askpass? (1=yes 0=no)
    20. %global no_gnome_askpass 1
    21. # Do we want to link against a static libcrypto? (1=yes 0=no)
    22. %global static_libcrypto 0
    23. # Do we want smartcard support (1=yes 0=no)
    24. %global scard 0
    25. # Use GTK2 instead of GNOME in gnome-ssh-askpass
    26. %global gtk2 1
    27. # Use build6x options for older RHEL builds
    28. # RHEL 7 not yet supported
    29. %if 0%{?rhel} > 6
    30. %global build6x 0
    31. %else
    32. %global build6x 1
    33. %endif
    34. %if 0%{?fedora} >= 26
    35. %global compat_openssl 1
    36. %else
    37. %global compat_openssl 0
    38. %endif
    39. # Do we want kerberos5 support (1=yes 0=no)
    40. %global kerberos5 1
    41. # Reserve options to override askpass settings with:
    42. # rpm -ba|--rebuild --define 'skip_xxx 1'
    43. %{?skip_x11_askpass:%global no_x11_askpass 1}
    44. %{?skip_gnome_askpass:%global no_gnome_askpass 1}
    45. # Add option to build without GTK2 for older platforms with only GTK+.
    46. # RedHat <= 7.2 and Red Hat Advanced Server 2.1 are examples.
    47. # rpm -ba|--rebuild --define 'no_gtk2 1'
    48. %{?no_gtk2:%global gtk2 0}
    49. # Is this a build for RHL 6.x or earlier?
    50. %{?build_6x:%global build6x 1}
    51. # If this is RHL 6.x, the default configuration has sysconfdir in /usr/etc.
    52. %if %{build6x}
    53. %global _sysconfdir /etc
    54. %endif
    55. # Options for static OpenSSL link:
    56. # rpm -ba|--rebuild --define "static_openssl 1"
    57. %{?static_openssl:%global static_libcrypto 1}
    58. # Options for Smartcard support: (needs libsectok and openssl-engine)
    59. # rpm -ba|--rebuild --define "smartcard 1"
    60. %{?smartcard:%global scard 1}
    61. # Is this a build for the rescue CD (without PAM, with MD5)? (1=yes 0=no)
    62. %global rescue 0
    63. %{?build_rescue:%global rescue 1}
    64. # Turn off some stuff for resuce builds
    65. %if %{rescue}
    66. %global kerberos5 0
    67. %endif
    68. Summary: The OpenSSH implementation of SSH protocol version 2.
    69. Name: openssh
    70. Version: %{ver}
    71. %if %{rescue}
    72. Release: %{rel}rescue
    73. %else
    74. Release: %{rel}
    75. %endif
    76. URL: https://www.openssh.com/portable.html
    77. Source0: https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-%{version}.tar.gz
    78. Source1: http://www.jmknoble.net/software/x11-ssh-askpass/x11-ssh-askpass-%{aversion}.tar.gz
    79. Source2: sshd.pam.el6
    80. %if ! %{no_build_openssl}
    81. Source3: https://www.openssl.org/source/openssl-%{opensslver}.tar.gz
    82. %endif
    83. License: BSD
    84. Group: Applications/Internet
    85. BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
    86. Obsoletes: ssh
    87. %if %{build6x}
    88. PreReq: initscripts >= 5.00
    89. %else
    90. Requires: initscripts >= 5.20
    91. %endif
    92. BuildRequires: perl
    93. #%if %{compat_openssl}
    94. #BuildRequires: compat-openssl10-devel
    95. #%else
    96. #BuildRequires: openssl-devel >= 1.0.1
    97. #BuildRequires: openssl-devel < 1.1
    98. #%endif
    99. BuildRequires: /bin/login
    100. %if ! %{build6x}
    101. BuildRequires: glibc-devel, pam
    102. %else
    103. BuildRequires: /usr/include/security/pam_appl.h
    104. %endif
    105. %if ! %{no_x11_askpass}
    106. BuildRequires: /usr/include/X11/Xlib.h
    107. # Xt development tools
    108. BuildRequires: libXt-devel
    109. # Provides xmkmf
    110. BuildRequires: imake
    111. # Rely on relatively recent gtk
    112. %if %{gtk2}
    113. BuildRequires: gtk2-devel
    114. %endif
    115. %endif
    116. %if ! %{no_gnome_askpass}
    117. BuildRequires: pkgconfig
    118. %endif
    119. %if %{kerberos5}
    120. BuildRequires: krb5-devel
    121. BuildRequires: krb5-libs
    122. %endif
    123. %package clients
    124. Summary: OpenSSH clients.
    125. Requires: openssh = %{version}-%{release}
    126. Group: Applications/Internet
    127. Obsoletes: ssh-clients
    128. %package server
    129. Summary: The OpenSSH server daemon.
    130. Group: System Environment/Daemons
    131. Obsoletes: ssh-server
    132. Requires: openssh = %{version}-%{release}, chkconfig >= 0.9
    133. %if ! %{build6x}
    134. Requires: /etc/pam.d/system-auth
    135. %endif
    136. %package askpass
    137. Summary: A passphrase dialog for OpenSSH and X.
    138. Group: Applications/Internet
    139. Requires: openssh = %{version}-%{release}
    140. Obsoletes: ssh-extras
    141. %package askpass-gnome
    142. Summary: A passphrase dialog for OpenSSH, X, and GNOME.
    143. Group: Applications/Internet
    144. Requires: openssh = %{version}-%{release}
    145. Obsoletes: ssh-extras
    146. %description
    147. SSH (Secure SHell) is a program for logging into and executing
    148. commands on a remote machine. SSH is intended to replace rlogin and
    149. rsh, and to provide secure encrypted communications between two
    150. untrusted hosts over an insecure network. X11 connections and
    151. arbitrary TCP/IP ports can also be forwarded over the secure channel.
    152. OpenSSH is OpenBSD's version of the last free version of SSH, bringing
    153. it up to date in terms of security and features, as well as removing
    154. all patented algorithms to separate libraries.
    155. This package includes the core files necessary for both the OpenSSH
    156. client and server. To make this package useful, you should also
    157. install openssh-clients, openssh-server, or both.
    158. %description clients
    159. OpenSSH is a free version of SSH (Secure SHell), a program for logging
    160. into and executing commands on a remote machine. This package includes
    161. the clients necessary to make encrypted connections to SSH servers.
    162. You'll also need to install the openssh package on OpenSSH clients.
    163. %description server
    164. OpenSSH is a free version of SSH (Secure SHell), a program for logging
    165. into and executing commands on a remote machine. This package contains
    166. the secure shell daemon (sshd). The sshd daemon allows SSH clients to
    167. securely connect to your SSH server. You also need to have the openssh
    168. package installed.
    169. %description askpass
    170. OpenSSH is a free version of SSH (Secure SHell), a program for logging
    171. into and executing commands on a remote machine. This package contains
    172. an X11 passphrase dialog for OpenSSH.
    173. %description askpass-gnome
    174. OpenSSH is a free version of SSH (Secure SHell), a program for logging
    175. into and executing commands on a remote machine. This package contains
    176. an X11 passphrase dialog for OpenSSH and the GNOME GUI desktop
    177. environment.
    178. %prep
    179. %if ! %{no_x11_askpass}
    180. %setup -q -a 1
    181. %else
    182. %setup -q
    183. %endif
    184. %if ! %{no_build_openssl}
    185. %define openssl_dir %{_builddir}/%{name}-%{version}/openssl
    186. mkdir -p openssl
    187. tar xfz %{SOURCE3} --strip-components=1 -C openssl
    188. pushd openssl
    189. ./config shared zlib -fPIC
    190. make %{?_smp_mflags}
    191. popd
    192. %endif
    193. %build
    194. %if %{rescue}
    195. CFLAGS="$RPM_OPT_FLAGS -Os"; export CFLAGS
    196. %endif
    197. export LD_LIBRARY_PATH="%{openssl_dir}"
    198. %configure \
    199. --sysconfdir=%{_sysconfdir}/ssh \
    200. --libexecdir=%{_libexecdir}/openssh \
    201. --datadir=%{_datadir}/openssh \
    202. --with-default-path=/usr/local/bin:/bin:/usr/bin \
    203. --with-superuser-path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin \
    204. --with-privsep-path=%{_var}/empty/sshd \
    205. --with-md5-passwords \
    206. --mandir=%{_mandir} \
    207. --with-mantype=man \
    208. --disable-strip \
    209. --with-ssl-dir="%{openssl_dir}" \
    210. %if %{scard}
    211. --with-smartcard \
    212. %endif
    213. %if %{rescue}
    214. --without-pam \
    215. %else
    216. --with-pam \
    217. %endif
    218. %if %{kerberos5}
    219. --with-kerberos5=$K5DIR \
    220. %endif
    221. %if %{static_libcrypto}
    222. #perl -pi -e "s|-lcrypto|%{_libdir}/libcrypto.a|g" Makefile
    223. perl -pi -e "s|-lcrypto|%{openssl_dir}/libcrypto.a -lpthread|g" Makefile
    224. %endif
    225. make %{?_smp_mflags}
    226. %if ! %{no_x11_askpass}
    227. pushd x11-ssh-askpass-%{aversion}
    228. %configure --libexecdir=%{_libexecdir}/openssh
    229. xmkmf -a
    230. make -j
    231. popd
    232. %endif
    233. # Define a variable to toggle gnome1/gtk2 building. This is necessary
    234. # because RPM doesn't handle nested %if statements.
    235. %if %{gtk2}
    236. gtk2=yes
    237. %else
    238. gtk2=no
    239. %endif
    240. %if ! %{no_gnome_askpass}
    241. pushd contrib
    242. if [ $gtk2 = yes ] ; then
    243. make gnome-ssh-askpass2
    244. mv gnome-ssh-askpass2 gnome-ssh-askpass
    245. else
    246. make gnome-ssh-askpass1
    247. mv gnome-ssh-askpass1 gnome-ssh-askpass
    248. fi
    249. popd
    250. %endif
    251. %install
    252. rm -rf $RPM_BUILD_ROOT
    253. mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/ssh
    254. mkdir -p -m755 $RPM_BUILD_ROOT%{_libexecdir}/openssh
    255. mkdir -p -m755 $RPM_BUILD_ROOT%{_var}/empty/sshd
    256. make install DESTDIR=$RPM_BUILD_ROOT
    257. echo -e 'PubkeyAcceptedAlgorithms +ssh-rsa\nUsePAM yes\nPermitRootLogin yes\nUseDNS no' >> $RPM_BUILD_ROOT/etc/ssh/sshd_config
    258. install -d $RPM_BUILD_ROOT/etc/pam.d/
    259. install -d $RPM_BUILD_ROOT/etc/rc.d/init.d
    260. install -d $RPM_BUILD_ROOT%{_libexecdir}/openssh
    261. install -m755 contrib/ssh-copy-id $RPM_BUILD_ROOT/usr/bin/ssh-copy-id
    262. install -m644 %{SOURCE2} $RPM_BUILD_ROOT/etc/pam.d/sshd
    263. install -m755 contrib/redhat/sshd.init $RPM_BUILD_ROOT/etc/rc.d/init.d/sshd
    264. %if ! %{no_x11_askpass}
    265. install x11-ssh-askpass-%{aversion}/x11-ssh-askpass $RPM_BUILD_ROOT%{_libexecdir}/openssh/x11-ssh-askpass
    266. ln -s x11-ssh-askpass $RPM_BUILD_ROOT%{_libexecdir}/openssh/ssh-askpass
    267. %endif
    268. %if ! %{no_gnome_askpass}
    269. install contrib/gnome-ssh-askpass $RPM_BUILD_ROOT%{_libexecdir}/openssh/gnome-ssh-askpass
    270. %endif
    271. %if ! %{scard}
    272. rm -f $RPM_BUILD_ROOT/usr/share/openssh/Ssh.bin
    273. %endif
    274. %if ! %{no_gnome_askpass}
    275. install -m 755 -d $RPM_BUILD_ROOT%{_sysconfdir}/profile.d/
    276. install -m 755 contrib/redhat/gnome-ssh-askpass.csh $RPM_BUILD_ROOT%{_sysconfdir}/profile.d/
    277. install -m 755 contrib/redhat/gnome-ssh-askpass.sh $RPM_BUILD_ROOT%{_sysconfdir}/profile.d/
    278. %endif
    279. perl -pi -e "s|$RPM_BUILD_ROOT||g" $RPM_BUILD_ROOT%{_mandir}/man*/*
    280. %clean
    281. rm -rf $RPM_BUILD_ROOT
    282. %triggerun server -- ssh-server
    283. if [ "$1" != 0 -a -r /var/run/sshd.pid ] ; then
    284. touch /var/run/sshd.restart
    285. fi
    286. %triggerun server -- openssh-server < 2.5.0p1
    287. # Count the number of HostKey and HostDsaKey statements we have.
    288. gawk 'BEGIN {IGNORECASE=1}
    289. /^hostkey/ || /^hostdsakey/ {sawhostkey = sawhostkey + 1}
    290. END {exit sawhostkey}' /etc/ssh/sshd_config
    291. # And if we only found one, we know the client was relying on the old default
    292. # behavior, which loaded the the SSH2 DSA host key when HostDsaKey wasn't
    293. # specified. Now that HostKey is used for both SSH1 and SSH2 keys, specifying
    294. # one nullifies the default, which would have loaded both.
    295. if [ $? -eq 1 ] ; then
    296. echo HostKey /etc/ssh/ssh_host_rsa_key >> /etc/ssh/sshd_config
    297. echo HostKey /etc/ssh/ssh_host_dsa_key >> /etc/ssh/sshd_config
    298. fi
    299. %triggerpostun server -- ssh-server
    300. if [ "$1" != 0 ] ; then
    301. /sbin/chkconfig --add sshd
    302. if test -f /var/run/sshd.restart ; then
    303. rm -f /var/run/sshd.restart
    304. /sbin/service sshd start > /dev/null 2>&1 || :
    305. fi
    306. fi
    307. %pre server
    308. %{_sbindir}/groupadd -r -g %{sshd_gid} sshd 2>/dev/null || :
    309. %{_sbindir}/useradd -d /var/empty/sshd -s /bin/false -u %{sshd_uid} \
    310. -g sshd -M -r sshd 2>/dev/null || :
    311. %post server
    312. /sbin/chkconfig --add sshd
    313. %postun server
    314. /sbin/service sshd condrestart > /dev/null 2>&1 || :
    315. %preun server
    316. if [ "$1" = 0 ]
    317. then
    318. /sbin/service sshd stop > /dev/null 2>&1 || :
    319. /sbin/chkconfig --del sshd
    320. fi
    321. %files
    322. %defattr(-,root,root)
    323. %doc CREDITS ChangeLog INSTALL LICENCE OVERVIEW README* PROTOCOL* TODO
    324. %attr(0755,root,root) %{_bindir}/scp
    325. %attr(0644,root,root) %{_mandir}/man1/scp.1*
    326. %attr(0755,root,root) %dir %{_sysconfdir}/ssh
    327. %attr(0600,root,root) %config(noreplace) %{_sysconfdir}/ssh/moduli
    328. %if ! %{rescue}
    329. %attr(0755,root,root) %{_bindir}/ssh-keygen
    330. %attr(0755,root,root) %{_bindir}/ssh-copy-id
    331. %attr(0644,root,root) %{_mandir}/man1/ssh-keygen.1*
    332. %attr(0755,root,root) %dir %{_libexecdir}/openssh
    333. %attr(4711,root,root) %{_libexecdir}/openssh/ssh-keysign
    334. %attr(0755,root,root) %{_libexecdir}/openssh/ssh-pkcs11-helper
    335. %attr(0755,root,root) %{_libexecdir}/openssh/ssh-sk-helper
    336. %attr(0644,root,root) %{_mandir}/man8/ssh-keysign.8*
    337. %attr(0644,root,root) %{_mandir}/man8/ssh-pkcs11-helper.8*
    338. %attr(0644,root,root) %{_mandir}/man8/ssh-sk-helper.8*
    339. %endif
    340. %if %{scard}
    341. %attr(0755,root,root) %dir %{_datadir}/openssh
    342. %attr(0644,root,root) %{_datadir}/openssh/Ssh.bin
    343. %endif
    344. %files clients
    345. %defattr(-,root,root)
    346. %attr(0755,root,root) %{_bindir}/ssh
    347. %attr(0644,root,root) %{_mandir}/man1/ssh.1*
    348. %attr(0644,root,root) %{_mandir}/man5/ssh_config.5*
    349. %attr(0644,root,root) %config(noreplace) %{_sysconfdir}/ssh/ssh_config
    350. %if ! %{rescue}
    351. %attr(2755,root,nobody) %{_bindir}/ssh-agent
    352. %attr(0755,root,root) %{_bindir}/ssh-add
    353. %attr(0755,root,root) %{_bindir}/ssh-keyscan
    354. %attr(0755,root,root) %{_bindir}/sftp
    355. %attr(0644,root,root) %{_mandir}/man1/ssh-agent.1*
    356. %attr(0644,root,root) %{_mandir}/man1/ssh-add.1*
    357. %attr(0644,root,root) %{_mandir}/man1/ssh-keyscan.1*
    358. %attr(0644,root,root) %{_mandir}/man1/sftp.1*
    359. %endif
    360. %if ! %{rescue}
    361. %files server
    362. %defattr(-,root,root)
    363. %dir %attr(0111,root,root) %{_var}/empty/sshd
    364. %attr(0755,root,root) %{_sbindir}/sshd
    365. %attr(0755,root,root) %{_libexecdir}/openssh/sftp-server
    366. %attr(0644,root,root) %{_mandir}/man8/sshd.8*
    367. %attr(0644,root,root) %{_mandir}/man5/moduli.5*
    368. %attr(0644,root,root) %{_mandir}/man5/sshd_config.5*
    369. %attr(0644,root,root) %{_mandir}/man8/sftp-server.8*
    370. %attr(0755,root,root) %dir %{_sysconfdir}/ssh
    371. %attr(0600,root,root) %config(noreplace) %{_sysconfdir}/ssh/sshd_config
    372. %attr(0600,root,root) %config(noreplace) /etc/pam.d/sshd
    373. %attr(0755,root,root) %config /etc/rc.d/init.d/sshd
    374. %endif
    375. %if ! %{no_x11_askpass}
    376. %files askpass
    377. %defattr(-,root,root)
    378. %doc x11-ssh-askpass-%{aversion}/README
    379. %doc x11-ssh-askpass-%{aversion}/ChangeLog
    380. %doc x11-ssh-askpass-%{aversion}/SshAskpass*.ad
    381. %{_libexecdir}/openssh/ssh-askpass
    382. %attr(0755,root,root) %{_libexecdir}/openssh/x11-ssh-askpass
    383. %endif
    384. %if ! %{no_gnome_askpass}
    385. %files askpass-gnome
    386. %defattr(-,root,root)
    387. %attr(0755,root,root) %config %{_sysconfdir}/profile.d/gnome-ssh-askpass.*
    388. %attr(0755,root,root) %{_libexecdir}/openssh/gnome-ssh-askpass
    389. %endif
    390. [root@localhost SPECS]#

    二、编译

    1、编译

    1. [root@localhost SPECS]# rpmbuild -bb openssh.spec
    2. warning: line 108: prereq is deprecated: PreReq: initscripts >= 5.00
    3. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.zWPwaj
    4. + umask 022
    5. + cd /root/rpmbuild/BUILD
    6. + LANG=C
    7. + export LANG
    8. + unset DISPLAY
    9. + cd /root/rpmbuild/BUILD
    10. + rm -rf openssh-9.4p1
    11. + /bin/tar -xf -
    12. + /usr/bin/gzip -dc /root/rpmbuild/SOURCES/openssh-9.4p1.tar.gz
    13. + STATUS=0
    14. + '[' 0 -ne 0 ']'
    15. + cd openssh-9.4p1
    16. ...
    17. Obsoletes: ssh-server
    18. Processing files: openssh-debuginfo-9.4p1-.el6.x86_64
    19. Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/openssh-9.4p1-.el6.x86_64
    20. Wrote: /root/rpmbuild/RPMS/x86_64/openssh-9.4p1-.el6.x86_64.rpm
    21. Wrote: /root/rpmbuild/RPMS/x86_64/openssh-clients-9.4p1-.el6.x86_64.rpm
    22. Wrote: /root/rpmbuild/RPMS/x86_64/openssh-server-9.4p1-.el6.x86_64.rpm
    23. Wrote: /root/rpmbuild/RPMS/x86_64/openssh-debuginfo-9.4p1-.el6.x86_64.rpm
    24. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.qcMTW9
    25. + umask 022
    26. + cd /root/rpmbuild/BUILD
    27. + cd openssh-9.4p1
    28. + rm -rf /root/rpmbuild/BUILDROOT/openssh-9.4p1-.el6.x86_64
    29. + exit 0
    30. [root@localhost SPECS]#

    看到“+ exit 0”表示编译成功。

    三、测试验证

    1、安装新编译的openssh RPM包

    1. [root@localhost SPECS]# cd /root/rpmbuild/RPMS/x86_64/
    2. [root@localhost x86_64]# ll
    3. 总用量 15132
    4. -rw-r--r--. 1 root root 4817808 9月 6 19:58 openssh-9.4p1-.el6.x86_64.rpm
    5. -rw-r--r--. 1 root root 4849872 9月 6 19:58 openssh-clients-9.4p1-.el6.x86_64.rpm
    6. -rw-r--r--. 1 root root 4362628 9月 6 19:58 openssh-debuginfo-9.4p1-.el6.x86_64.rpm
    7. -rw-r--r--. 1 root root 1451744 9月 6 19:58 openssh-server-9.4p1-.el6.x86_64.rpm
    8. [root@localhost x86_64]# yum install *
    9. 已加载插件:fastestmirror
    10. 设置安装进程
    11. 诊断 openssh-9.4p1-.el6.x86_64.rpm: openssh-9.4p1-.el6.x86_64
    12. openssh-9.4p1-.el6.x86_64.rpm 将作为 openssh-5.3p1-123.el6_9.x86_64 的更新
    13. Loading mirror speeds from cached hostfile
    14. 诊断 openssh-clients-9.4p1-.el6.x86_64.rpm: openssh-clients-9.4p1-.el6.x86_64
    15. openssh-clients-9.4p1-.el6.x86_64.rpm 将被安装
    16. 诊断 openssh-debuginfo-9.4p1-.el6.x86_64.rpm: openssh-debuginfo-9.4p1-.el6.x86_64
    17. openssh-debuginfo-9.4p1-.el6.x86_64.rpm 将被安装
    18. 诊断 openssh-server-9.4p1-.el6.x86_64.rpm: openssh-server-9.4p1-.el6.x86_64
    19. openssh-server-9.4p1-.el6.x86_64.rpm 将作为 openssh-server-5.3p1-123.el6_9.x86_64 的更新
    20. 解决依赖关系
    21. --> 执行事务检查
    22. ---> Package openssh.x86_64 0:5.3p1-123.el6_9 will be 升级
    23. ---> Package openssh.x86_64 0:9.4p1-.el6 will be an update
    24. ---> Package openssh-clients.x86_64 0:9.4p1-.el6 will be 安装
    25. ---> Package openssh-debuginfo.x86_64 0:9.4p1-.el6 will be 安装
    26. ---> Package openssh-server.x86_64 0:5.3p1-123.el6_9 will be 升级
    27. ---> Package openssh-server.x86_64 0:9.4p1-.el6 will be an update
    28. --> 完成依赖关系计算
    29. 依赖关系解决
    30. =========================================================================================================================================================
    31. 软件包 架构 版本 仓库 大小
    32. =========================================================================================================================================================
    33. 正在安装:
    34. openssh-clients x86_64 9.4p1-.el6 /openssh-clients-9.4p1-.el6.x86_64 12 M
    35. openssh-debuginfo x86_64 9.4p1-.el6 /openssh-debuginfo-9.4p1-.el6.x86_64 17 M
    36. 正在升级:
    37. openssh x86_64 9.4p1-.el6 /openssh-9.4p1-.el6.x86_64 12 M
    38. openssh-server x86_64 9.4p1-.el6 /openssh-server-9.4p1-.el6.x86_64 3.5 M
    39. 事务概要
    40. =========================================================================================================================================================
    41. Install 2 Package(s)
    42. Upgrade 2 Package(s)
    43. 总文件大小:44 M
    44. 确定吗?[y/N]:y
    45. 下载软件包:
    46. 运行 rpm_check_debug
    47. 执行事务测试
    48. 事务测试成功
    49. 执行事务
    50. 正在升级 : openssh-9.4p1-.el6.x86_64 1/6
    51. 正在升级 : openssh-server-9.4p1-.el6.x86_64 2/6
    52. 正在安装 : openssh-clients-9.4p1-.el6.x86_64 3/6
    53. 正在安装 : openssh-debuginfo-9.4p1-.el6.x86_64 4/6
    54. 清理 : openssh-server-5.3p1-123.el6_9.x86_64 5/6
    55. 清理 : openssh-5.3p1-123.el6_9.x86_64 6/6
    56. Verifying : openssh-debuginfo-9.4p1-.el6.x86_64 1/6
    57. Verifying : openssh-server-9.4p1-.el6.x86_64 2/6
    58. Verifying : openssh-9.4p1-.el6.x86_64 3/6
    59. Verifying : openssh-clients-9.4p1-.el6.x86_64 4/6
    60. Verifying : openssh-5.3p1-123.el6_9.x86_64 5/6
    61. Verifying : openssh-server-5.3p1-123.el6_9.x86_64 6/6
    62. 已安装:
    63. openssh-clients.x86_64 0:9.4p1-.el6 openssh-debuginfo.x86_64 0:9.4p1-.el6
    64. 更新完毕:
    65. openssh.x86_64 0:9.4p1-.el6 openssh-server.x86_64 0:9.4p1-.el6
    66. 完毕!

    2、版本验证:

    可以将/root/rpmbuild/RPMS/x86_64下的软件包进行拷贝分发或放到http服务器共享。至此,rpm包制作完成。

    3、注意事项

    openssh升级到9.*后加密算法最低要求256位,因此升级openssh后低版本的客户端和CRT都将无法连接,报以下错误:

    Key exchange failed.
    No compatible key-exchange method. The server supports these methods: sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256

    此时其它未升级openssh的centos6服务器都连不上更新服务器的,不要以为升级失败了,只需将需要连接本服务器的主机的openssh-client也升级了即可。

    Windows连接请升级SecureCRT到8.*.*版本,同时会话属性中仅启用256或512位算法,即可正常连接。

    可以看到连接是没有任何问题的。

     本人编译的成品包下载地址:下载链接

  • 相关阅读:
    Docker在Centos7下的安装
    做销售,如何实现快速初筛客户?
    shell脚本之数组
    MySQL 内部组件结构以及SQL执行逻辑
    信息学奥赛一本通:1147:最高分数的学生姓名
    docker导致root空间满进入不了系统解决方案
    【QSPI】 什么是QSPI SPI和QSPI异同
    c++11 标准模板(STL)string(四)
    是真的吗?Nuture子刊告诉你这么多年的微生物组经验都是错的?!
    docker&docker-copose_限制容器cpu和内存
  • 原文地址:https://blog.csdn.net/forestqq/article/details/132685885