ssh服務(wù)可以很方便的通過(guò)網(wǎng)絡(luò)登錄到linux開發(fā)板,同時(shí)支持sftp協(xié)議向開發(fā)板傳輸文件。下面簡(jiǎn)單講下移植過(guò)程。
開發(fā)板環(huán)境:
名稱:imx283內(nèi)核:linux2.6.35.31.下載源碼zlib下載openssl下載openssh下載
建議先下載openssh,openssh也不要下載最新版本,zlib和openssl的版本最好早于openssh的版本,因?yàn)閛penssh的編譯會(huì)用到zlib和openssl生成的庫(kù) ,若zlib和openssl的版本比openssh新,可能在編譯openssh時(shí)出現(xiàn)不兼容等問(wèn)題。
我這里下載的是zlib-1.2.8、openssl-1.0.2、openssh-7.1p1。
2.zlib編譯
解壓zlib-1.2.8,進(jìn)入zlib根目錄
1>./configure –Static –prefix=/test/open-ssh/zlib/ 生成makefile
–static 表示生成靜態(tài)庫(kù) 也可以使用–share生成動(dòng)態(tài)庫(kù)
–prefix 指定make install的安裝目錄2>修改makefile 更換編譯器為交叉編譯器 CC=arm-fsl-linux-gnueabi-gcc LDSHAred=arm-fsl-linux-gnueabi-gcc CPP=arm-fsl-linux-gnueabi-gcc -E AR=arm-fsl-linux-gnueabi-ar
3>make 4>make install
3.openssl編譯
解壓openssl源碼,進(jìn)入源碼根目錄
1.配置 openssl的新舊版本配置方式有點(diǎn)不同,具體配置方式可以查看./configure -h
1.1.1版本配置:
代碼語(yǔ)言:JavaScript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
./Configure linux-generic32 no-asm shared no-async --prefix=/test/open-ssh/open-ssl1/ CROSS_COMPILE=/ZLG_linux/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-fsl-linux-gnueabi- CC=gcc -fPIC
linux-generic32:32位系統(tǒng) no-asm:在交叉編譯過(guò)程中不使用匯編代碼代碼加速編譯過(guò)程 shared:生成動(dòng)態(tài)連接庫(kù) no-async:不使用GNU的ucontext庫(kù) 交叉編譯工具鏈沒(méi)有提供GNU C的ucontext庫(kù) –prefix:指定install輸出的目錄 CROSS_COMPILE:指定編譯器,需要絕對(duì)路徑 -fPIC全稱是position Independent Code,用于生成位置無(wú)關(guān)代碼,代碼無(wú)絕對(duì)跳轉(zhuǎn),都是相對(duì)跳轉(zhuǎn)。
1.0.2版本配置:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
./Configure --prefix=/test/open-ssh/open-ssl/ os/compiler:/ZLG_linux/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-fsl-linux-gnueabi-gcc
–prefix 指定make install的安裝目錄
這里交叉編譯器路徑最好使用絕對(duì)路徑
2.編譯 make 3.安裝 make install
4.openssh編譯
解壓openssh源碼,進(jìn)入源碼主目錄
1.配置 生成MakeFile
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
./configure --host=arm-fsl-linux-gnueabi --with-libs --with-zlib=/test/open-ssh/zlib --with-ssl-dir=/test/open-ssh/open-ssl --disable-etc-default-login CC=arm-fsl-linux-gnueabi-gcc AR=arm-fsl-linux-gnueabi-ar
這里需要指定剛剛安裝的zlib和openssl目錄
2.編譯
make
5.拷貝openssh相關(guān)文件和密鑰
這部分工作包括新建文件夾、將生成的sshd相關(guān)工具拷貝到各個(gè)文件夾、生成密鑰。我把這些寫成了一個(gè)shell腳本pack.sh,該腳本首先新建一個(gè)usr文件夾,然后在usr下新建需要的各級(jí)子文件夾,接著會(huì)生成需要的密鑰并把需要的sshd相關(guān)工具和密鑰拷貝到這些文件夾,最后將usr下所有文件打包 并生成usr.tar.bz2壓縮包。
注意:pack.sh需要放在openssh源碼根目錄下運(yùn)行
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
#!/bin/bashfile_a="scp sftp ssh ssh-add ssh-agent ssh-keygen ssh-keyscan" file_b="moduli ssh_config sshd_config" file_c="sftp-server ssh-keysign"key="ssh_host_rsa_key ssh_host_dsa_key ssh_host_ecdsa_key ssh_host_ed25519_key" mkdir -p usr/local/bin usr/local/etc usr/libexec mkdir usr/sbin/for i in $file_adoif [ -f $i ];thencp $i usr/local/bin/echo "cp $i ok" elseecho "error:$i not exist " exit_script fidonefor i in $file_bdoif [ -f $i ];thencp $i usr/local/etc/echo "cp $i ok"elseecho "error:$i not exist"exit_script fidonefor i in $file_cdo if [ -f $i ];then cp $i usr/libexec echo "cp $i ok" else echo "error:$i not exist" exit_script fidoneif [ -f "sshd" ];thencp sshd usr/sbin/echo "cp sshd ok"elseecho "error:sshd not exist"exit_scriptfi# ssh_host_rsa_keyif [ -f "ssh_host_rsa_key" ];thenecho "ssh_host_rsa_key exist"cp ssh_host_rsa_key usr/local/etc/echo "cp ssh_host_rsa_key ok" elsessh-keygen -t rsa -f ssh_host_rsa_key -N ""cp ssh_host_rsa_key usr/local/etc/echo "cp ssh_host_rsa_key ok" fi# ssh_host_dsa_keyif [ -f "ssh_host_dsa_key" ];thenecho "ssh_host_dsa_key exist"cp ssh_host_dsa_key usr/local/etc/echo "cp ssh_host_dsa_key ok" elsessh-keygen -t dsa -f ssh_host_dsa_key -N ""cp ssh_host_dsa_key usr/local/etc/echo "cp ssh_host_dsa_key ok" fi# ssh_host_ecdsa_keyif [ -f "ssh_host_ecdsa_key" ];thenecho "ssh_host_ecdsa_key exist"cp ssh_host_ecdsa_key usr/local/etc/echo "cp ssh_host_ecdsa_key ok" elsessh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""cp ssh_host_ecdsa_key usr/local/etc/echo "cp ssh_host_ecdsa_key ok" fi# ssh_host_ed25519_keyif [ -f "ssh_host_ed25519_key" ];thenecho "ssh_host_ed25519_key exist"chmod 600 ssh_host_ed25519_keycp ssh_host_ed25519_key usr/local/etc/echo "cp ssh_host_ed25519_key ok" elsessh-keygen -t dsa -f ssh_host_ed25519_key -N ""chmod 600 ssh_host_ed25519_keycp ssh_host_ed25519_key usr/local/etc/echo "cp ssh_host_ed25519_key ok" fitar -cjvf usr.tar.bz2 usr/*echo "pack usr to usr.tar.bz2 ok"
生成usr.tar.bz2壓縮包之后,將該壓縮包拷貝到開發(fā)板的根目錄下并解壓,壓縮包內(nèi)的usr目錄會(huì)和開發(fā)板根目錄下的usr合并。
6.拷貝openssh運(yùn)行需要的動(dòng)態(tài)庫(kù)
首先可以在openssh源碼根目錄下運(yùn)行:arm-fsl-linux-gnueabi-readelf -d sshd 就可以知道sshd需要哪些動(dòng)態(tài)庫(kù)

如果你開發(fā)板的文件系統(tǒng)能夠運(yùn)行起來(lái),那么其中的大部分庫(kù)應(yīng)該是有的,缺少的可能是libcrypt.so.1和libz.so.1,libcrypt.so.1在openssl源碼根目錄下可以找到,libz.so.1在libz源碼的根目錄下。將缺少的庫(kù)拷貝到開發(fā)板/lib下即可。
7.修改SSHD配置、增加root用戶密碼將開發(fā)板/usr/local/etc/sshd_config,將PermitRootLogin yes前的注釋“#”號(hào)去掉,若沒(méi)有這一句,增加這一句即可。開發(fā)板執(zhí)行passwd root,給root用戶增加密碼,若之前有密碼,這一步可跳過(guò)。開發(fā)板打開 /etc/passwd 文件,在最后添加一行:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin開發(fā)板打開/etc/init.d/rcS,在最后增加一句:/usr/sbin/sshd &,讓ssh服務(wù)開機(jī)在后臺(tái)啟動(dòng)(必須保證此時(shí)網(wǎng)卡已經(jīng)配置好,否則啟動(dòng)ssh服務(wù)需要放到網(wǎng)卡配置后面)
最后重啟開發(fā)板!
8.測(cè)試
首先執(zhí)行ps,看下ssh服務(wù)是否已經(jīng)啟動(dòng)

用secureCRT或者其他ssh工具連接開發(fā)板!
部分用xshell工具的同學(xué)可能會(huì)遇到下面的問(wèn)題:
WARNING! The remote SSH server rejected X11 forwarding request. 解決辦法:xshell——會(huì)話——屬性——隧道——取消勾選X11轉(zhuǎn)發(fā)
參考博客:
1.成功移植 SSH 服務(wù)到 ARM 開發(fā)板上
2.移植 ssh 到開發(fā)板
3.12個(gè)移植OpenSSH 到 ARM Linux 開發(fā)板上常見錯(cuò)誤總結(jié)