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

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值