Android安裝ssh服務


1、安裝條件

需要安裝ssh服務的手機需要有root權限,我測試使用的手機是工程樣機,adb連接上以后默認有root權限;
其他用戶需要先root才能進行,可能需要把一些命令放到腳本中,放到手機中運行,並且在運行前切換到root權限。

2、下載文件

busybox 下載地址 http://www.busybox.net/downloads/binaries
dropbear 下載地址 http://www.cri.ch/sven/lib/exe/fetch.php/blog/dropbear.zip

3、登錄密鑰

客戶端使用的是SecureCRT,由於使用私鑰登錄,首先需要創建密鑰對;
步驟: “工具”->“創建公鑰...”,密鑰類型“DSA”(“RSA”應該也可以),通行短語就留空(否則登錄需要輸入密碼),密鑰長度默認1024位,選擇“OpenSSH密鑰格式”,選擇一個文件夾保存密鑰,同時會生成私鑰Identity和公鑰Identity.pub;

4、安裝busybox

adb remount
adb push busybox /system/xbin/
adb shell
adb shell chmod 0755 /system/xbin/busybox
adb shell busybox --install -s /system/xbin/

5、安裝dropbear

adb remount
:: 將dropbear相關的文件push進手機
adb push dropbear /system/xbin/
adb push dropbearkey /system/xbin/
adb push dropbearconvert /system/xbin/
adb shell chmod 0744 /system/xbin/dropbear*
:: 創建dropbear的目錄
adb shell mkdir /data/dropbear
adb shell mkdir /data/dropbear/.ssh
:: 生成服務器密鑰
adb shell dropbearkey -t dss -f /data/dropbear/dss_host_key
:: 將登陸密鑰放置到服務器
adb push Identity.pub /data/dropbear/.ssh/
adb shell mv /data/dropbear/.ssh/Identity.pub /data/dropbear/.ssh/authorized_keys
adb shell chmod 744 /data/dropbear/.ssh/authorized_keys
:: 腳本會創建用戶相關的配置文件,否則無法登陸 adb push createfiles.sh /data/dropbear adb shell chmod -R 0744 /data/dropbear adb shell /data/dropbear/createfiles.sh :: 啟動服務器測試  (實際應用可以去掉-F選項,運行於后台) adb shell dropbear -d /data/dropbear/dss_host_key -F -E -s -v

createfiles.sh內容: 

echo "root:x:0:0::/root:/system/bin/sh" > /etc/passwd
echo "root::14531:0:99999:7:::" > /etc/shadow
echo "root:x:0:" > /etc/group
echo "root:!::" > /etc/gshadow
echo "/system/bin/sh" > /etc/shells
echo "PATH=\"/usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/data/local/bin\"" > /etc/profile
echo "export PATH" >> /etc/profile

6、卸載dropbear

adb remount
adb shell rm /system/xbin/dropbear
adb shell rm /system/xbin/dropbearkey
adb shell rm /system/xbin/dropbearconvert
adb shell rm -rf /data/dropbear
adb shell rm /etc/passwd
adb shell rm /etc/shadow
adb shell rm /etc/group
adb shell rm /etc/gshadow
adb shell rm /etc/shells
adb shell rm /etc/profile

7、參考

Running dropbear on Android: http://www.cri.ch/sven/doku.php/blog/running-dropbear-on-android


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM