openssh-7.8p1編譯安裝

實際需求:

因安全漏洞問題,openssh須要升級,
可是Centos6系統倉庫裏沒有最新的rpm包。因此只能手動編譯安裝openssh最新版本
Centos7系統的就不必了,倉庫自帶的版本已經知足要求。目前最新應該是7.4p1.固然若是要編譯和6沒啥區別。
注意一點就是:7的/etc/rc.d/rc.local 默認無執行權限 ,須要 chmod +x /etc/rc.d/rc.local 而後 /etc/init.d/sshd_7.8 start 寫在這裏。html

參考資料:

https://blog.csdn.net/lqy461929569/article/details/76148598
https://www.xj123.info/7111.html
官方安裝指導書:
http://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssh.htmlnode

注意事項:

一、須要開啓telnet以防ssh服務出問題。
二、重啓後ssh服務要能啓動
三、防火牆端口注意放行linux

留好退路

1、升級以前最好先把telnet開起來,防止意外致使ssh沒法鏈接vim

一、yum install telnet-server 會本身安裝xinetd安全

二、chkconfig --listbash

openssh-7.8p1編譯安裝

三、編輯 /etc/xinetd.d/telnetapp

#sed -r 's/disable([[:space:]])=([[:space:]])no/disable\1=\2yes/g' /etc/xinetd.d/telnetssh

sed -i '/disable/s/yes/no/g' telnetide

讓telnet託管給xinetdsvn

四、此時,便可用非root用戶進行登陸。若要使用root用戶登陸,通常有如下兩種方法(二選一):

(1)mv /etc/securetty /etc/securetty.bak

PS:網上有說將你的登陸終端信息加入到此文件下,經過你的/var/log/secure日誌,添加要放行的終端,可是不靠譜,一直在變的,強烈不建議使用。

(2)修改/etc/pam.d/login這個文件,註釋下面這一行,
#auth xxxxxxxxx pam_securetty.so 註釋這行

PS:親測,這個方法很差使,沒效果。

注意:ssh測試能夠登陸後,將上面的2個文件再改回去。

五、驗證telnet能夠正常登陸

準備戰鬥

1、卸載當前yum安裝的openssh相關軟件包,避免干擾。

卸載前備份下/etc/init.d/sshd文件,用於自啓動。固然本身也能夠編輯。編譯會本身生成。

rpm -e --nodeps `rpm -qa |grep openssh`

openssh一搬會默認安裝三個包

openssh
openssh-clients
openssh-server

rpm -qa openssh* # 檢查下是否卸載完了

ss -ntl |grep 22

2、安裝相關依賴包,開始安裝。

1)openssh須要依賴openssl。

查看解壓的tar包中的INSTALL文件。裏邊有依賴的包版本信息。
zlib
openssl

cd /tmp
wget https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.8p1.tar.gz
tar xf openssh-7.8p1.tar.gz
cd openssh-7.8p1

2)編譯前查看相關文件,雖然英文不太好,可是很重要。
openssh-7.8p1編譯安裝

3)就編譯安裝而言,有三種方式。
一、默認安裝方式
二、指定安裝目錄
三、指定

cat INSTALL

對比下rpm安裝後的目錄結構。
openssh-7.8p1編譯安裝
openssh-7.8p1編譯安裝
一、默認安裝
./configure
make
make install
說明:
This will install the OpenSSH binaries in /usr/local/bin, configuration file in /usr/local/etc, the server in /usr/local/sbin, etc.

二、指定安裝目錄

./configure --prefix=/opt
make
make install

說明:
To specify a different installation prefix, use the --prefix option to configure:
Will install OpenSSH in /opt/{bin,etc,lib,sbin}.

三、指定各個安裝目錄

./configure --prefix=/opt --sysconfdir=/etc/ssh
make
make install

說明:
You can also override specific paths, for example:
This will install the binaries in /opt/{bin,lib,sbin}, but will place the configuration files in /etc/ssh.

PS:就實際我的體驗而言,

第一種和第三種:看着方便,缺點可能就是太分散
第二種:卸載版本方便。刪除安裝目錄便可,綠色安裝。缺點須要本身添加一些環境變量,這個咱們能夠經過stow工具緩解這個缺點。

打掃戰場

1、安裝後相關設置。

1)指定環境變量

不是默認安裝位置,須要作bin文件的PATH變量指定。

cat >/etc/profile.d/openssh.sh <<-"EOF"
#!/bin/bash
openssh_path=/usr/local/app/openssh
PATH="$openssh_path/bin:$openssh_path/sbin:$PATH"
export PATH
EOF

2)服務自啓動

sshd啓動主要是配置文件。

解壓編譯的目錄下是有自啓動腳本的。

openssh-7.8p1編譯安裝
可是,這個是沒有指定chkconfig參數,不能被chkconfig管理自啓動。
須要手動添加。
或者去sshd.init文件中將chkconfig這段指定copy到opensshd.init文件中。
openssh-7.8p1編譯安裝

cp -a openssd.init /etc/init.d/sshd_7.8
chkconfig --add sshd_7.8
chkconfig --list sshd_7.8 默認是開啓2,3,4,5級別。

3)添加幫助文檔路徑。

cat  >> /etc/man.config <<eof
#start custom
MANPATH_MAP     /usr/local/app/openssh/bin                 /usr/local/app/openssh/share/man
MANPATH_MAP     /usr/local/app/openssh/sbin                 /usr/local/app/openssh/share/man
#end custom
eof

4) 修改配置文件、

vim /usr/local/app/openssh/etc/sshd_config
    AddressFamily inet #只監聽ipv4地址,不監聽ipv6
    PermitRootLogin yes # 容許root用戶登陸。固然最好不要容許root登陸,新的配置文件,優化的已經不錯了。

5)重啓服務,測試啓動腳本的有效性。重啓電腦,測試重啓後,服務的有效性

service sshd_7.8 restart

6)關閉xinetd服務,刪除防火牆規則。還原修改的文件。

service xinetd stopchkconfig xinetd offmv /etc/securetty.bak /etc/securetty

相關文章
相關標籤/搜索