測試環境
電腦: macOS Mojave
手機: Huawei Mate10Pronode
Termux是Android上的一個很是強大的終端模擬器。
強大之處在於支持使用apt安裝zsh、git、vim、python、ruby、nodejs、openssh、gcc、golang等幾乎全部經常使用的終端軟件.python
Termux官網:https://termux.com/git
安裝好Termux後,點擊圖標進入,依次輸入如下命令。
申請讀寫權限,要否則有時手機會找不到生成的文件golang
termux-setup-storage $ ls storage $ cd storage/ $ ls # 這些會連接到手機的相應目錄 dcim downloads movies music pictures shared
apt update apt install openssh
sshd
手機端已經安裝好後openssh,並已啓動服務。vim
電腦生成過密鑰
ssh-keygen
而後進入電腦.ssh目錄,將id_rsa.pub文件拷貝到手機的storage/shared目錄下。ruby
添加公鑰信息
確保id_rsa.pub存在於storage/shared/目錄下,進入手機Termux。依次輸入如下命令。ssh
cd cp storage/shared/id_rsa.pub ./.ssh cat id_rsa.pub >> authorized_keys
至此,已添加公鑰信息到手機。測試
whoami
ifconfig -a
假設手機使用whoami查看的用戶名是u0_a258,手機的ip地址是192.168.1.9code
則電腦ssh到手機ip
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
接下來自由發揮...