Termux怎么登录VPS?_详细步骤教你用手机远程管理服务器

如何在Termux中通过SSH登录VPS服务器?

步骤 操作内容 所需工具/命令
1 安装SSH客户端 pkg install openssh
2 启动SSH服务 sshd
3 获取连接信息 whoami, ifconfig
4 设置用户密码 passwd
5 连接VPS ssh username@vpsip -p port

Termux登录VPS的完整指南

在移动设备上管理服务器已经成为现代开发者的常见需求,Termux作为Android上的强大终端工具,可以让你随时随地登录和管理VPS。

主要操作步骤概览

步骤 操作说明 关键命令
1. 环境准备 确保Termux和网络连接正常 -
2. 安装SSH 安装OpenSSH客户端工具 pkg install openssh
3. 连接VPS 使用SSH命令远程登录 ssh user@ip -p port

详细操作流程

步骤1:环境准备与检查

操作说明:首先确保Termux正常运行,并检查网络连接状态。 使用工具提示:Termux内置了基本的网络诊断工具。 操作界面模拟
# 检查网络连接
$ ping -c 4 google.com
PING google.com (142.251.42.78): 56 data bytes
64 bytes from 142.251.42.78: icmpseq=0 ttl=116 time=12.345 ms
64 bytes from 142.251.42.78: icmpseq=1 ttl=116 time=11.234 ms

检查Termux版本

$ termux-info Packages CPU architecture: aarch64 Subscribed repositories:...

步骤2:安装SSH客户端

操作说明:Termux默认不包含SSH客户端,需要手动安装OpenSSH包。 使用工具提示:使用pkg包管理器进行安装。 操作界面模拟
# 更新软件包列表
$ pkg update
Hit:1 https://termux.org/packages stable InRelease

安装OpenSSH

$ pkg install openssh Reading package lists... Done Building dependency tree... Done The following NEW packages will be installed: openssh 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 1254 kB of archives. After this operation, 3256 kB of additional disk space will be used. Do you want to continue? [Y/n] y

步骤3:获取VPS连接信息

操作说明:在登录前需要准备好VPS的IP地址、端口号、用户名和密码。 使用工具提示:确保你拥有正确的VPS访问凭证。 操作界面模拟
# 查看当前Termux用户名(用于理解用户名格式)
$ whoami
u0a256

检查网络接口信息(可选)

$ ifconfig wlan0 wlan0: ip 192.168.1.101 netmask 0xffffff00 broadcast 192.168.1.255

步骤4:建立SSH连接

操作说明:使用ssh命令连接到目标VPS服务器。 使用工具提示:基本连接格式为:ssh 用户名@服务器IP -p 端口号。 操作界面模拟
# 使用密码登录VPS
$ ssh root@123.45.67.89 -p 22
The authenticity of host '123.45.67.89 (123.45.67.89)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '123.45.67.89' (ECDSA) to the list of known hosts.
root@123.45.67.89's password: 
Last login: Fri Oct 31 21:25:33 2025 from 192.168.1.101
[root@vps ~]# 

步骤5:使用密钥认证(推荐)

操作说明:为提高安全性,建议使用SSH密钥对代替密码登录。 使用工具提示:需要在本地生成密钥对,并将公钥上传到VPS。 操作界面模拟
# 在Termux中生成SSH密钥对
$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/data/data/com.termux/files/home/.ssh/idrsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /data/data/com.termux/files/home/.ssh/idrsa
Your public key has been saved in /data/data/com.termux/files/home/.ssh/idrsa.pub

将公钥复制到VPS

$ ssh-copy-id -i ~/.ssh/id
rsa.pub root@123.45.67.89 -p 22

使用密钥登录

$ ssh -i ~/.ssh/idrsa root@123.45.67.89 -p 22

常见问题与解决方案

问题 原因 解决方案
“Connection refused” 错误 VPS的SSH服务未启动或防火墙阻止 检查VPS上ssh服务状态:systemctl status sshd,并确保防火墙开放相应端口
“Permission denied” 错误 用户名或密码错误,或密钥认证失败 确认登录凭证正确,检查密钥文件权限:chmod 600 ~/.ssh/idrsa
网络连接超时 网络问题或VPS IP地址错误 使用ping命令测试网络连通性,确认VPS IP地址正确
Termux无法安装软件包 软件源配置问题 更换Termux软件源:apt edit-sources,使用清华镜像源
SSH连接成功后立即断开 客户端或服务器配置问题 在ssh命令中添加-o ServerAliveInterval=60参数保持连接

通过以上步骤,你可以在Termux中成功登录并管理VPS服务器,实现移动办公和远程运维的需求

发表评论

评论列表