最近的,openssl/openssh等相继漏洞的暴露,让暴露在公网的linux.沦陷为肉鸡的正营。。。

没办法,还是升级版本。。。

00、openssh简介

  OpenSSH 是一组安全远程的连接工具,主要包括了几个部份:ssh、sshd、scp、sftp、ssh-keygen、ssh-agent、ssh-add等

ssh(SSH 客户端,用于登录建立连接,是 rlogin 与 Telnet的安全替代方案)
sshd (SSH 服务端,典型的独立守护进程)
scp、sftp (文件安全传输工具,rcp、ftp 安全的替代方案)
ssh-keygen (用于产生 RSA 或 DSA 密钥)
ssh-agent、ssh-add(帮助用户不需要每次都要输入金钥密码的工具)

01、编译前的准备工作

下载openssh:

  https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/

A: 已经安装了openssl(新版本的,编译安装的)

B:或者基于本机的openssl(yum install -y openssl-devel

openssl version -a   #查看当前版本的openssl

ssh  -V                     #当前openssh编译的版本

yum install -y zlib-devel  #如果编译参数压缩的需要安装

02、编译安装 OpenSSH

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh2  --with-ssl-dir=/usr/local/openssl #如果openssl已经基于源码升级需要加此参数,但基于本机openssl的不需要添加
make -j4 && make install

解释:
--prefix 安装目录
--sysconfdir 配置文件目录  #当前的/etc/ssh   目的不覆盖,也可以基于本机直接覆盖安装
--with-ssl-dir 指定 OpenSSL 的安装目录(基于源码安装的)

03、备份OpenSSH 旧配置文件

mv  /etc/init.d/sshd   /etc/init.d/sshd.bak

04、修改ssh启动脚本

openssh-7.4p1\contrib\redhat\sshd.init sshd就是根据sshd,init修改的针对redhat发行版本

根据实际情况修正的sshd脚本  /etc/init.d/sshd

#!/bin/bash
#
# Init file for OpenSSH server daemon
#
# chkconfig:
# description: OpenSSH server daemon
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
# config: /etc/ssh/ssh_host_key.pub
# config: /etc/ssh/ssh_random_seed
# config: /etc/ssh/sshd_config
# pidfile: /var/run/sshd.pid # source function library
. /etc/rc.d/init.d/functions # pull in sysconfig settings
[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd RETVAL=
prog="sshd" # Some functions to make the below more readable
SSHD=/usr/local/openssh/sbin/sshd #按实际情况调整
PID_FILE=/var/run/sshd.pid do_restart_sanity_check()
{
$SSHD -t
RETVAL=$?
if [ $RETVAL -ne ]; then
failure $"Configuration file or keys are invalid"
echo
fi
} start()
{
# Create keys if necessary
/usr/local/openssh/bin/ssh-keygen -A #按实际情况调整
if [ -x /sbin/restorecon ]; then
/sbin/restorecon /etc/ssh2/ssh_host_key.pub
/sbin/restorecon /etc/ssh2/ssh_host_rsa_key.pub
/sbin/restorecon /etc/ssh2/ssh_host_dsa_key.pub
/sbin/restorecon /etc/ssh2/ssh_host_ecdsa_key.pub
fi echo -n $"Starting $prog:"
$SSHD $OPTIONS && success || failure
RETVAL=$?
[ $RETVAL -eq ] && touch /var/lock/subsys/sshd
echo
} stop()
{
echo -n $"Stopping $prog:"
killproc $SSHD -TERM
RETVAL=$?
[ $RETVAL -eq ] && rm -f /var/lock/subsys/sshd
echo
} reload()
{
echo -n $"Reloading $prog:"
killproc $SSHD -HUP
RETVAL=$?
echo
} case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
condrestart)
if [ -f /var/lock/subsys/sshd ] ; then
do_restart_sanity_check
if [ $RETVAL -eq ] ; then
stop
# avoid race
sleep
start
fi
fi
;;
status)
status $SSHD
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=
esac
exit $RETVAL

chmod +x /etc/init.d/sshd

添加允许root远程登录
/etc/ssh2/sshd_config
PermitRootLogin yes

05、设置环境变量

vim /etc/profile
export PATH=/usr/local/openssh/bin:$PATH

source /etc/profile

06、开机自启动 sshd

service sshd restart

chkconfig sshd on

07、openssh编译参数

[root@rhel openssh-7.4p1]# ./configure --help
`configure' configures OpenSSH Portable to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']

Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/openssh]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]

System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]

Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--disable-largefile omit support for large files
--disable-pkcs11 disable PKCS#11 support code [no]
--disable-strip Disable calling strip(1) on install
--disable-etc-default-login Disable using PATH from /etc/default/login no
--disable-lastlog disable use of lastlog even if detected no
--disable-utmp disable use of utmp even if detected no
--disable-utmpx disable use of utmpx even if detected no
--disable-wtmp disable use of wtmp even if detected no
--disable-wtmpx disable use of wtmpx even if detected no
--disable-libutil disable use of libutil (login() etc.) no
--disable-pututline disable use of pututline() etc. (uwtmp) no
--disable-pututxline disable use of pututxline() etc. (uwtmpx) no

Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--without-openssl Disable use of OpenSSL; use only limited internal crypto **EXPERIMENTAL**
--with-ssh1 Enable support for SSH protocol 1
--without-stackprotect Don't use compiler's stack protection
--without-hardening Don't use toolchain hardening flags
--without-rpath Disable auto-added -R linker paths
--with-cflags Specify additional flags to pass to compiler
--with-cppflags Specify additional flags to pass to preprocessor
--with-ldflags Specify additional flags to pass to linker
--with-libs Specify additional libraries to link with
--with-Werror Build main code with -Werror
--with-solaris-contracts Enable Solaris process contracts (experimental)
--with-solaris-projects Enable Solaris projects (experimental)
--with-solaris-privs Enable Solaris/Illumos privileges (experimental)
--with-osfsia Enable Digital Unix SIA
--with-zlib=PATH Use zlib in PATH
--without-zlib-version-check Disable zlib version check
--with-skey[=PATH] Enable S/Key support (optionally in PATH)
--with-ldns[=PATH] Use ldns for DNSSEC support (optionally in PATH)
--with-libedit[=PATH] Enable libedit support for sftp
--with-audit=module Enable audit support (modules=debug,bsm,linux)
--with-pie Build Position Independent Executables if possible
--with-ssl-dir=PATH Specify path to OpenSSL installation   #源码编译openssl需要指定
--without-openssl-header-check Disable OpenSSL version consistency check
--with-ssl-engine Enable OpenSSL (hardware) ENGINE support
--with-prngd-port=PORT read entropy from PRNGD/EGD TCP localhost:PORT
--with-prngd-socket=FILE read entropy from PRNGD/EGD socket FILE (default=/var/run/egd-pool)
--with-pam Enable PAM support
--with-pam-service=name Specify PAM service name
--with-privsep-user=user Specify non-privileged user for privilege separation
--with-sandbox=style Specify privilege separation sandbox (no, capsicum, darwin, rlimit, seccomp_filter, systrace, pledge)
--with-selinux Enable SELinux support
--with-kerberos5=PATH Enable Kerberos 5 support
--with-privsep-path=xxx Path for privilege separation chroot (default=/var/empty)
--with-xauth=PATH Specify path to xauth program
--with-maildir=/path/to/mail Specify your system mail directory
--with-mantype=man|cat|doc Set man page type
--with-md5-passwords Enable use of MD5 passwords
--without-shadow Disable shadow password support
--with-ipaddr-display Use ip address instead of hostname in $DISPLAY
--with-default-path= Specify default $PATH environment for server
--with-superuser-path= Specify different path for super-user
--with-4in6 Check for and convert IPv4 in IPv6 mapped addresses
--with-bsd-auth Enable BSD auth support
--with-pid-dir=PATH Specify location of ssh.pid file
--with-lastlog=FILE|DIR specify lastlog location common locations

Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

OpenSSH has been configured with the following options:
User binaries: /usr/local/openssh/bin
System binaries: /usr/local/openssh/sbin
Configuration files: /etc/ssh2
Askpass program: /usr/local/openssh/libexec/ssh-askpass
Manual pages: /usr/local/openssh/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/openssh/bin
Manpage format: doc
PAM support: no
OSF SIA support: no
KerberosV support: no
SELinux support: no
Smartcard support:
S/KEY support: no
MD5 password support: no
libedit 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: rlimit

Host: x86_64-pc-linux-gnu
Compiler: gcc
Compiler flags: -g -O2 -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security
-Wno-pointer-sign -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-all -fPIE Preprocessor flags: -I/usr/local/openssl/include
Linker flags: -L/usr/local/openssl/lib -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-
protector-all -pie Libraries: -lcrypto -lrt -ldl -lutil -lz -lcrypt -lresolv

基于源码编译安装openssh的更多相关文章

  1. Linux 从源码编译安装 OpenSSH

    https://blog.csdn.net/bytxl/article/details/46639073 Linux 从源码编译安装 OpenSSH以及各问题解决 2015年06月25日 17:37: ...

  2. SSH/SSL 源码编译安装简易操作说明

    环境:CentOS 6.7 安全加固需求,由于某盟扫描系统主机有SSL系列漏洞,客户要求必须修复: 解决方案:将SSH/SSL升级到最新版本,删除SSL旧版本(实测不删除旧版本某盟扫描无法通过). 当 ...

  3. Centos7.X 源码编译安装subversion svn1.8.x

    说明:SVN(subversion)的运行方式有两种:一种是基于Apache的http.https网页访问形式:还有一种是基于svnserve的独立服务器模式.SVN的数据存储方式也有两种:一种是在B ...

  4. Nginx 最新版源码编译安装 包含常用模块作用及所需依赖

    第一部分 Nginx最新版源码编译安装 1. 使用的模块 模块1:http_rewrite_module 基于正则匹配来实现重定向.依赖PCRE库,见依赖1 模块2:http_gzip_module ...

  5. CentOS7.6源码编译安装PHP 7.3.8

    安装步骤 PHP官网下载链接:https://www.php.net/downloads.php 1. 使用wget命令下载源码安装包 wget https://www.php.net/distrib ...

  6. centos 7 下 rabbitmq 3.8.0 & erlang 22.1 源码编译安装

    centos 7 下 rabbitmq 3.8.0 & erlang 22.1 源码编译安装 安装前请检查好erlang和rabbitmq版本是否相匹配参考:RabbitMQ Erlang V ...

  7. Httpd服务进阶知识-LAMP源码编译安装

    Httpd服务进阶知识-LAMP源码编译安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 想必大家都知道,动态资源交给fastcgi程序处理,静态资源依旧由httpd服务器处理  ...

  8. Dubbo入门到精通学习笔记(十九):MySQL源码编译安装、MySQL主从复制的配置

    文章目录 MySQL 源码编译安装(CentOS-6.6+MySQL-5.6) 一.服务器配置: 二.源码安装 MySQL5.6.26: MySQL主从复制的配置 环境 依赖课程 MySQL 主从复制 ...

  9. Centos 7源码编译安装 php7.1 之生产篇

    Centos 7源码编译安装 php7.1 之生产篇 Published 2017年4月30日 by Node Cloud 介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具 ...

随机推荐

  1. Go语言之进阶篇请求报文格式分析

    1. 请求报文格式分析 示例: package main import ( "fmt" "net" ) func main() { //监听 listener, ...

  2. go语言之进阶篇通过switch实现类型断言

    1.通过switch实现类型断言 示例: package main import "fmt" type Student struct { name string id int } ...

  3. [leetcode]Subsets @ Python

    原题地址:https://oj.leetcode.com/problems/subsets/ 题意:枚举所有子集. 解题思路:碰到这种问题,一律dfs. 代码: class Solution: # @ ...

  4. jquery ajax 的 $.get()用法详解

    js文件 $(document).ready(function(){ $("form").submit(function(event) {event.preventDefault( ...

  5. 微信小程序wxml文件中调用自定义函数

    想在微信小程序的wxml文件里自如的像vue那样调用自定义的方法,发现并不成功,得利用WXS脚本语言. WXS脚本语言是 WeiXin Script 脚本语言的简称,是JavaScript.JSON. ...

  6. 解决EditPlus在设置了UTF-8之后,编写的HTML页面仍出现汉字乱码问题

    解决EditPlus在设置了UTF-8之后.编写的HTML页面仍出现汉字乱码问题   相信有些同学在使用EditPlus编写HTML页面时发现,尽管已经设置好了UTF-8的编码格式.但却发现HTML页 ...

  7. Java对象的序列化和反序列化源码阅读

    前言 序列化和反序列化看起来用的不多,但用起来就很关键,因为稍一不注意就会出现问题.序列化的应用场景在哪里?当然是数据存储和传输.比如缓存,需要将对象复刻到硬盘存储,即使断电也可以重新反序列化恢复.下 ...

  8. GIT 如何合并另一个远程Git仓库的文件到本地仓库里某个指定子文件夹并不丢失远程提交记录?

    问题背景:     最近在重新整理手中的一个项目,目前该项目分为PC项目,手机项目,某第三方接口项目,第三方接口服务项目和手机项目     因为之前规划的原因,原来的四个项目是分两个解决方案来管理的 ...

  9. mac 苹果鼠标 magic mouse2 当触摸代替点击当触摸板教程

    本文解决 mac 苹果鼠标 magic mouse2 触摸代替点击,鼠标当触摸板教程 买了magic mouse2之后,发现官方不推荐使用触摸代替点击,我感觉很不爽,这不就是一个触摸板嘛,于是各种搜软 ...

  10. windows server 2012 st 版本的php环境问题修复 与删除

    windows server 2012 st 版本的php环境问题修复 错误内容 HTTP 错误 500.0 - Internal Server Error C:\Program Files\iis ...