Android安裝ssh服務

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   ar   os   使用   sp   

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 remountadb push busybox /system/xbin/adb shelladb shell chmod 0755 /system/xbin/busyboxadb 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/dropbearadb 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 push createfiles.sh /data/dropbearadb shell chmod -R 0744 /data/dropbearadb 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/passwdecho "root::14531:0:99999:7:::" > /etc/shadowecho "root:x:0:" > /etc/groupecho "root:!::" > /etc/gshadowecho "/system/bin/sh" > /etc/shellsecho "PATH=\"/usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/data/local/bin\"" > /etc/profileecho "export PATH" >> /etc/profile

6、卸載dropbear

adb remountadb shell rm /system/xbin/dropbearadb shell rm /system/xbin/dropbearkeyadb shell rm /system/xbin/dropbearconvertadb shell rm -rf /data/dropbearadb shell rm /etc/passwdadb shell rm /etc/shadowadb shell rm /etc/groupadb shell rm /etc/gshadowadb shell rm /etc/shellsadb shell rm /etc/profile

7、參考

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

Android安裝ssh服務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.