[英]How to start SSH on a chroot Linux
我設法通過終端在Android手機上啟動Linux,甚至啟動SSH服務並使用ConnectBot對其進行了測試。 但是,這是手動操作。 我更多地考慮了自動執行此操作的方法。
我使用了這種Linux機制: http : //mitchtech.net/android-backtrack-chroot/
我相信我的主要問題是,在chroot
完成之前和之后,我正在嘗試執行一些步驟,這似乎在Android應用程序上不起作用:
Runtime.getRuntime().exec("su");
//Mount the image
Runtime.getRuntime().exec("startbt");
//chroot into Linux
Runtime.getRuntime().exec("bt");
//From inside chroot, start the ssh service
Runtime.getRuntime().exec("/etc/init.d/ssh start");
這似乎也不起作用:
Runtime.getRuntime().exec("su & startbt & bt & /etc/init.d/ssh start");
我再次猜測這是一個問題,它被解釋為chroot內部或外部。 我最終的主要任務是自動啟動SSH服務,而不必通過Android應用程序啟動。
如果執行
Runtime.getRuntime().exec("su");
這只會啟動su
,然后退出。 下一個執行程序將不會以提升的特權執行。 同樣,在執行bt
之后,不會在chroot環境中執行下一個命令。
我認為bt
是腳本嗎? 您可以更改它以將參數傳遞給chroot
,因此可以將執行命令傳遞給它,例如:
...
chroot new_root /etc/init.d/ssh start
...
要運行此命令,您需要使用-c
選項將命令直接傳遞給su
。 並且您需要將命令作為String數組傳遞(或使用ProcessBuilder
):
Runtime.getRuntime().exec(new String[] {"su", "-c", "startbt; bt"});
另一種選擇是使bt
從命令行將參數傳遞給chroot:
chroot new_root "$@"
然后在命令行上傳遞它們:
Runtime.getRuntime().exec(new String[] {"su", "-c", "startbt; bt /etc/init.d/ssh start"});
除非您真的想用這種方式做事,否則我將只下載SSH服務器應用程序。
我個人使用SSHDroid 。
https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&hl=en
但是從外觀上看,您正在構建自己的應用程序以自行啟動內置的ssh服務器嗎? 因此,您可能已經知道可以使用應用程序進行操作了。
無論如何,祝你好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.