1. 程式人生 > >ubuntu14.04.1升級openssh

ubuntu14.04.1升級openssh

公鑰 修改 -a 再次 0.0.0.0 默認安裝 端口 記得 正常的

由於ubuntu14.04.1默認的openssh是5.6p1版的,有很多安全漏洞,所以計劃升級至openssh7.5p1
一、下載升級所需的軟件
zlib-1.2.11.tar.gz openssh-7.5p1.tar.gz openssl-1.0.2l.tar.gz

二、需要卸載舊的版本
#apt-get remove openssl
#apt-get remove openssh-server openssh-client
#apt-get purge openssl
三、開始安裝
1、首先解壓安裝zlib:tar -zxvf zlib-1.2.11.tar.gz,會在當前目錄下生成zlib目錄。進入zlib目錄,然後./configure、make、 make install ,一路下來,沒有錯誤提示,則安裝成功。

2、先安裝openssl, 一定記得加上--shared選項, 否則openssh編譯的時候會找不到新安裝的openssl的library, 會報錯: openssl的 header和library版本不匹配。
#cd /openssl-1.0.2l
#./configure --prefix=/usr --shared
#make
#make test
#make install
安裝完後,可使用openssl version -a 檢查openssl是否安裝正確。

這裏安裝有可能會報錯:POD document had syntax errors at /usr/bin/pod2man line 71.

解決方法:打開/usr/bin/pod2man 這個配置文件看一下 可以的話 註釋掉 第71行 在編譯 用#註釋

  3、再安裝openssh-server。步驟同上。
#./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-zlib --with-ssl-dir=/usr/local/openssl --with-privsep-path=/var/lib/sshd --with-pam
#make clean
#make
#make install
在最後一步報錯: Privilege separation user sshd does not exist 解決:在/etc/passwd 中加入: sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

再次make install 編譯安裝成功。
註:如果遇到庫文件找不到
技術分享圖片
則要比對正常的機器和這臺的libcrypto.so.1.0.0的文件大小,如果文件為0則要用正常的文件覆蓋它(系統裏會有多個這個文件,分布在不同的目錄下),如果發現和正常的機器比有缺失,則拷貝到那個目錄。

  4、啟動ssh。ssh默認安裝在/usr/local/sbin/目錄下,使用 /usr/local/sbin/sshd 啟動ssh服務,該服務默認偵聽22端口。

  5、檢查ssh服務是否啟動:

netstat -tnlp|grep :22
#ssh -V
OpenSSH_7.5p1, OpenSSL 1.0.2l 25 May 2017

--查看ssh服務
#/usr/sbin/sshd -d
#netstat -tnlp | grep :22
tcp 0 0 0.0.0.0:22 0.0.0.0: LISTEN 2204/sshd
tcp 0 0 :::22 :::
LISTEN 2204/sshd

最後,ubuntu如果重啟後,sshd默認是不會開機啟動的,所以要添加開機自啟動

sudo vi /etc/rc.local

在exit 0之前,增加一行:

/usr/local/sbin/sshd

也可以這樣
--設置開機自啟動
cp -p /usr/local/openssh-7.5p1/contrib/redhat/sshd.init /etc/init.d/sshd
chmod+x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
chkconfig --list sshd

附錄:
卸載zlib,錯誤處理
rpm-qa | grep zlib
zlib-1.2.3-29.el6.x86_64
rpm -e--nodeps zlib-1.2.3-29.el6.x86_64
rpm-qa | grep zlib
rpm:error while loading shared libraries: libz.so.1: cannot open shared objectfile: No such file or directory
--解決辦法
ldd/bin/rpm |grep libz.so.1
libz.so.1 => not found
libz.so.1 => not found
libz.so.1 => not found
libz.so.1 => not found
libz.so.1 => not found

find /-name libz.so.1
/lib64/libz.so.1
ll /lib64/libz.so.1
lrwxrwxrwx.1 root root 13 11月 16 2013 /lib64/libz.so.1 -> libz.so.1.2.3
從另外一臺linux上拷貝libz.so.1.2.3放到/lib64/目錄下,創建連接
cd /lib64/
ln -slibz.so.1.2.3 libz.so.1

yum install pam-dev
Therewas a problem importing one of the Python modules
requiredto run yum. The error leading to this problem was:

libssl.so.10: cannot open shared objectfile: No such file or directory
libcrypto.so.10: cannot open shared objectfile: No such file or directory
解決辦法:
cd /usr/lib64/
ln-s libssl.so.1.0.0 libssl.so.10
ln-s libcrypto.so.1.0.0 libcrypto.so.10

掛載光盤,用ISO
sudo mount /dev/sr0 /mnt
命令被執行後,反饋“mount: /dev/sr0 is write-protected, mounting read-only”,意思是以只讀的方式對光盤進行了掛載。

ubuntu的yum配置
ubuntu是不支持yum命令的,自己就嘗試了一下ubuntu yum命令的安裝,安裝過程如下(ubuntu版本是14.04)

1、首先檢測是否安裝了build-essential程序包

apt-get install build-essential
2、安裝yum
apt-get install yum

ubuntu自己的包管理
/etc/apt/sources.list 是包管理工具 apt 所用的記錄軟件包倉庫位置的配置文件,同樣的還有位於 /etc/apt/sources.list.d/*.list 的各文件。
編輯其中的語句
deb [arch=amd64] http://11.11.177.72:28000 ngiam main
其他外部源
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
然後保存,sudo apt upgrade(更新)

在ubuntu上ssh出現permission denied (publickey,password)問題:

修改/etc/ssh/sshd-config文件.
將其中的PermitRootLogin no修改為yes
PubkeyAuthentication yes修改為no
AuthorizedKeysFile .ssh/authorized_keys前面加上#屏蔽掉,
PasswordAuthentication no修改為yes就可以了。

重啟sshd即可:service sshd restart

其實這種方法不能解決公鑰的問題,只是改為了以password方式訪問

ubuntu14.04.1升級openssh