Linux Ubuntu openssh离线源码安装、升级版本

Linux Ubuntu openssh离线源码安装、升级版本

一、设备环境

1.操作系统

Ubuntu 16.04.1

root@Lemon:/home/lemon# uname -a
Linux Lemon 4.15.0-34-generic #37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2.现在的openssh版本

OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g 1 Mar 2016

root@Lemon:/home/lemon# ssh V
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016

二、openssh官网下载源码

官网:https://www.openssh.com/
下载:https://www.openssh.com/portable.html
最新版本:https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

官网最新可用生产版本openssh-8.6p1
在这里插入图片描述

这次下载 https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz 的源码包。

三、安装openssh

1.解压源码包

将openssh源码包解压,并进入openssh-8.6p1文件夹

root@Lemon:/home# tar -zxf openssh-8.6p1.tar.gz 
root@Lemon:/home# cd openssh-8.6p1
2.查看README
root@Lemon:/home/openssh-8.6p1# vim README                      //查看帮助

在这里插入图片描述

下图是安装openssh的预制环境条件,由于是升级版本操作,以下环境已经安装过。
在这里插入图片描述

查看INSTALL

root@Lemon:/home/openssh-8.6p1# vim INSTALL 

在这里插入图片描述

3.编译源码

接下来根据Quick Start直接编译

root@Lemon:/home/openssh-8.6p1# ./configure 
root@Lemon:/home/openssh-8.6p1# ......
......
hecking if getpgrp accepts zero args... yes
checking openssl/opensslv.h usability... yes
checking openssl/opensslv.h presence... yes
checking for openssl/opensslv.h... yes
checking OpenSSL header version... 30000000 (OpenSSL 3.0.0-alpha17 20 May 2021)
checking for OpenSSL_version... no
checking for OpenSSL_version_num... no
checking OpenSSL library version... not found
configure: error: OpenSSL library not found.

报错了,说是没找到OpenSSL 依赖库,因为安装了openssl,那就尝试加参数指定依赖库位置。

./configure --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/lib
root@Lemon:/home/openssh-8.6p1# ./configure --with-ssl-dir=/usr/local/ssl --with-zlib=/usr/local/lib
root@Lemon:/home/openssh-8.6p1# ......
OpenSSH has been configured with the following options:
                     User binaries: /usr/local/bin
                   System binaries: /usr/local/sbin
               Configuration files: /usr/local/etc
                   Askpass program: /usr/local/libexec/ssh-askpass
                      Manual pages: /usr/local/share/man/manX
                          PID file: /var/run
  Privilege separation chroot path: /var/empty
            sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
                    Manpage format: doc
                       PAM support: no
                   OSF SIA support: no
                 KerberosV support: no
                   SELinux support: no
              MD5 password support: no
                   libedit support: no
                   libldns support: no
  Solaris process contract support: no
           Solaris project support: no
         Solaris privilege support: no
       IP address in $DISPLAY hack: no
           Translate v4 in v6 hack: yes
                  BSD Auth support: no
              Random number source: OpenSSL internal ONLY
             Privsep sandbox style: seccomp_filter
                   PKCS#11 support: yes
                  U2F/FIDO support: yes
          Host: x86_64-pc-linux-gnu
      Compiler: cc
Compiler flags: -g -O2 -pipe -Wall -Wextra -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong -fPIE  

Preprocessor flags: -I/usr/local/ssl -I/usr/local/lib  -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE
      Linker flags: -L/usr/local/ssl -L/usr/local/lib  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie 
         Libraries: -lcrypto -ldl -lutil -lz  -lcrypt -lresolv

root@Lemon:/home/openssh-8.6p1# make
root@Lemon:/home/openssh-8.6p1# ......
root@Lemon:/home/openssh-8.6p1# make install
root@Lemon:/home/openssh-8.6p1# ......

至此,编译、安装过程中无任何报错,一路畅通,然后查看openssh版本。

root@Lemon:/home/openssh-8.6p1# ssh -V
OpenSSH_8.6p1, OpenSSL 3.0.0-alpha17 20 May 2021

四、报错异常

报错提示说是没找到OpenSSL 依赖库,因为安装了openssl,checking OpenSSL header version 时候也能够拿到OpenSSL的版本信息,需要加参数手动指定依赖库位置。

checking OpenSSL header version... 30000000 (OpenSSL 3.0.0-alpha17 20 May 2021)
checking for OpenSSL_version... no
checking for OpenSSL_version_num... no
checking OpenSSL library version... not found
configure: error: OpenSSL library not found.

configure提供如下常用指定参数

--prefix					安装目录
--sysconfdir				配置文件目录
--with-ssl-dir				指定 OpenSSL 的安装目录
--with-privsep-path			非特权用户的chroot目录
--with-privsep-user=sshd	指定非特权用户为sshd
--with-zlib					指定zlib库的安装目录
--with-md5-passwords		支持读取经过MD5加密的口令
--with-ssl-engine			启用OpenSSL的ENGINE支持

在这里插入图片描述

可以如下代码样配置

./configure --prefix=/usr/local --sysconfdir=/usr/local/ssh --with-ssl-dir=/usr/local/ssl --with-privsep-path=/var/empty --with-privsep-user=sshd --with-zlib=/usr/local/lib --with-ssl-engine --with-md5-passwords --disable-etc-default-login

五、openssh用法

官网Manual https://www.openssh.com/manual.html

配置文件路径/etc/ssh/

root@Lemon:/etc/ssh# ls
moduli      sshd_config       ssh_host_dsa_key.pub  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub
ssh_config  ssh_host_dsa_key  ssh_host_ecdsa_key    ssh_host_ed25519_key    ssh_host_rsa_key

配置文件:

root@Lemon:/etc/ssh# cat sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile	%h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

重启ssh服务生效

systemctl restart sshd
或
systemctl restart ssh

停止ssh服务

systemctl stop sshd

查看ssh服务状态

root@Lemon:/etc/ssh# systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since 四 2021-06-17 15:37:13 CST; 1s ago
 Main PID: 13283 (sshd)
   CGroup: /system.slice/ssh.service
           └─13283 /usr/sbin/sshd -D

6月 17 15:37:13 Lemon systemd[1]: Starting OpenBSD Secure Shell server...
6月 17 15:37:13 Lemon sshd[13283]: Server listening on 0.0.0.0 port 22.
6月 17 15:37:13 Lemon sshd[13283]: Server listening on :: port 22.
6月 17 15:37:13 Lemon systemd[1]: Started OpenBSD Secure Shell server.

六、openssh一键安装脚本

一键安装版本install.sh,openssh-8.6p1版本

#!/bin/sh

echo "1s后开始解压...\n"
sleep 1s
tar -zxvf openssh-8.6p1.tar.gz -C /home/

echo "解压成功...\进入/home/openssh-8.6p1\n"
cd /home/openssh-8.6p1

echo "1s后开始编译...\n"
sleep 1s
./configure

echo "1s后开始编译...\n"
sleep 1s
make

echo "1s后开始安装...\n"
sleep 1s
make install

echo "openssh安装完成...\nssh -V\n"
openssl -V

在这里插入图片描述

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
以下是在Linux系统中离线安装OpenSSH的步骤: 1. 下载OpenSSH的源代码包,可以从OpenSSH官方网站下载最新版本的源代码包。 2. 将源代码包解压缩到任意目录下。 3. 安装编译OpenSSH所需的依赖包,包括zlib、openssl、libedit等。可以使用以下命令安装: ``` yum install zlib-devel openssl-devel libedit-devel ``` 4. 进入OpenSSH源代码目录,运行以下命令: ``` ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-tcp-wrappers --with-ssl-dir=/usr/local/ssl ``` 这个命令将会检查系统依赖是否满足OpenSSH的编译要求,并生成Makefile文件。 参数说明: --prefix:指定OpenSSH安装后的根目录,默认为/usr/local。 --sysconfdir:指定OpenSSH的配置文件目录,默认为/etc/ssh。 --with-pam:启用PAM认证支持。 --with-zlib:启用zlib压缩支持。 --with-tcp-wrappers:启用TCP Wrapper支持。 --with-ssl-dir:指定OpenSSL安装路径。 5. 运行make命令编译OpenSSH。 ``` make ``` 6. 运行make install命令安装OpenSSH。 ``` make install ``` 安装完成后,可以使用以下命令检查OpenSSH是否安装成功: ``` ssh -V ``` 如果输出了OpenSSH版本信息,则说明安装成功。 7. 配置OpenSSH。 配置文件位于/etc/ssh/sshd_config,可以根据需要修改配置文件中的参数。 修改完成后,使用以下命令重启OpenSSH服务: ``` systemctl restart sshd ``` 至此,OpenSSH离线安装就完成了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

byzf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值