1. 程式人生 > >Openssh arm移植經驗記錄

Openssh arm移植經驗記錄

Openssh arm移植經驗記錄

參考資料:
https://blog.csdn.net/yasirliberty/article/details/51274971
https://blog.csdn.net/zhongruixian/article/details/21076405
https://blog.csdn.net/shjhuang/article/details/56830864
https://blog.csdn.net/ygy6146/article/details/52453490

由於公司產品被安全掃描到有ssh安全漏洞,發現版本還是4.6,因此決定升級到7.7,參考了網上的資料,經過了無數失敗和重啟,總算搞定了,記錄如下:

升級過程基本同參考資料的描述,按順序安裝zlib,openssl和openssh
1.下載zlib-1.2.3.tar.gz
https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.3/zlib-1.2.3.tar.gz
2. 下載openssl-1.0.2k.tar.gz
https://www.openssl.org/source/openssl-1.0.2k.tar.gz
3. 下載
http://mirrors.evowise.com/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz

一、交叉編譯軟體
安裝zlib很順利,按照文件一步步做就好了
./configure --shared --prefix=/root/temp/bin/zlib(這裡是你要安裝的目錄)
進入Makefile裡,把
將CC,CPP,AR,LDSHARED這幾個的值加上字首arm-linux-gnueabihf-
(這裡要說一點,arm-linux-gnueabihf-gcc這個我沒安裝,一開始的機器上少了一個ar,openssl編譯的時候一直不成功,後來偷懶,換了個有這個環境的機器)
編譯,make;make install

二、openssl
安裝openssl就比較痛苦,折騰了一天,先用最新的1.1.1版本,死活編譯不通過,最終換成1.0.2p,經過反覆測試,總算成功了,而且因為configure引數不對,導致openssh編譯配置檔案無法生成,後面反覆編譯了幾次

./Configure --prefix=/root/temp/bin/openssl os/compiler:/opt/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin/arm-linux-gnueabihf-gcc

注意:這個 --fPIC一定要加,不然後面openssh編譯會出錯,我在這裡卡了很久
編譯,make;make install

三、openssh
這個也是反覆編譯了很久,開始一直不能生成makefile檔案,不得已,我只有通過sh -x 除錯模式分析,最後修改configure檔案裡的內容,才完成了配置檔案的生成
修改的內容是:要把配置生成腳本里的/usr/local/ssl內容替換成你自己已經編譯好的openssl目錄,我這裡是/root/temp/bin/openssl ,感覺下面語句了ssl-dir沒起作用

./configure --host=arm-linux-gnueabihf --with-ssl-dir=/root/temp/bin/openssl --with-zlib=/root/temp/bin/zlib --prefix=/usr/local --disable-etc-default-login CC=arm-linux-gnueabihf-gcc AR=arm-linux-gnueabihf-ar

這裡prefix也坑了我一把,編譯好的檔案放在板子上,提示找不到對應目錄下的sshd_config,只好修改prefix,重新編譯一遍

編譯:make,不用make install,因為我們不是升級ubuntu的openssh

四、移植
這個相對簡單,按照文件說明,把幾個需要的檔案cp到板子上就好了,可以自己做個指令碼,方便後面批量升級
scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan 拷貝到目標板/usr/sbin
sshd_config拷貝到目標板/usr/local/etc
sftp-server ssh-keysign 拷貝到目標板 /usr/libexec
sshd 拷貝到目標板 /usr/sbin/
在板子/usr/local/etc目錄下執行:
ssh-keygen -t rsa -f ssh_host_rsa_key -N “”
ssh-keygen -t dsa -f ssh_host_dsa_key -N “”
ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N “”
ssh-keygen -t dsa -f ssh_host_ed25519_key -N “”

修改目標板passwd檔案(這步我沒做,因為原來就有)
在/etc/passwd 中新增下面這一行
sshd❌74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin

五、驗證
做完這些,先/sbin/sshd重啟sshd,驗證移植是否成功
然後修改sshd_config檔案

PasswordAuthentication yes
PermitRootLogin yes
前面的註釋去掉,否則會出現遠端ssh把密碼錯誤,無法登陸的問題

最後重啟板子,確認登陸無異常,完成移植。