通过ssh登录到手机 Termux
测试环境
电脑: macOS Mojave
手机: Huawei Mate10Pro
Termux是Android上的一个非常强大的终端模拟器。
强大之处在于支持使用apt安装zsh、git、vim、python、ruby、nodejs、openssh、gcc、golang等几乎所有常用的终端软件.
Termux官网:https://termux.com/
安装openssh
安装好Termux后,点击图标进入,依次输入以下命令。
申请读写权限,要不然有时手机会找不到生成的文件
termux-setup-storage
$ ls
storage
$ cd storage/
$ ls
# 这些会链接到手机的相应目录
dcim downloads movies music pictures shared
安装openssh
apt update
apt install openssh
启动sshd服务
sshd
手机端已经安装好后openssh,并已启动服务。
配置登录密钥
-
电脑生成过密钥
ssh-keygen
然后进入电脑.ssh目录,将id_rsa.pub文件拷贝到手机的storage/shared目录下。 -
添加公钥信息
确保id_rsa.pub存在于storage/shared/目录下,进入手机Termux。依次输入以下命令。
cd
cp storage/shared/id_rsa.pub ./.ssh
cat id_rsa.pub >> authorized_keys
至此,已添加公钥信息到手机。
手机查看当前用户名
whoami
手机查看当前ip
ifconfig -a
电脑ssh到手机
假设手机使用whoami查看的用户名是u0_a258,手机的ip地址是192.168.1.9
则电脑ssh到手机
ssh u0_a258@192.168.31.9 -p 8022
mac-abeen:~ abeen$ ssh u0_a258@192.168.31.9
ssh: connect to host 192.168.31.9 port 22: Connection refused
mac-abeen:~ abeen$ ssh u0_a258@192.168.31.9 -p 8022
The authenticity of host '[192.168.31.9]:8022 ([192.168.31.9]:8022)' can't be established.
ECDSA key fingerprint is SHA256:odVWNFTp19bl1BJ0LBwKhuBnSVkFNar0ZKWh1gZ4pJ4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.31.9]:8022' (ECDSA) to the list of known hosts.
Welcome to Termux!
Wiki: https://wiki.termux.com
Community forum: https://termux.com/community
IRC channel: #termux on freenode
Gitter chat: https://gitter.im/termux/termux
Mailing list: termux+subscribe@groups.io
Search packages: pkg search <query>
Install a package: pkg install <package>
Upgrade packages: pkg upgrade
Learn more: pkg help
$ ls
abeen.txt storage
接下来自由发挥...