Android安装ssh服务

来源:互联网 发布:微博 知乎 编辑:程序博客网 时间:2024/06/11 03:44

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 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/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

0 0
原创粉丝点击