Git 与 SSH:Operit 终端里的版本控制与远程连接
Git 配置
# 预装确认
git --version
# 配置用户信息(首次使用必做)
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main
日常 Git 操作
# Clone 仓库
cd ~/projects
git clone https://github.com/example/repo.git
cd repo
# 日常流程
git status # 查看修改
git add . # 暂存所有改动
git commit -m "fix: adjust config"
git push origin main
# 分支管理
git checkout -b feature/new-feature
# ... 修改代码 ...
git checkout main
git merge feature/new-feature
# 临时存改
git stash # 存起来
git stash pop # 恢复
SSH 远程连接
生成密钥对
# 如果还没密钥
ssh-keygen -t ed25519 -C "operit-on-phone"
# 公钥位置
cat ~/.ssh/id_ed25519.pub
复制公钥内容,到目标服务器或 GitHub/GitLab 的 SSH Keys 设置页添加。
连接服务器
ssh user@192.168.1.100
ssh -i ~/.ssh/id_ed25519 user@server.example.com -p 2222
Operit 终端里的 SSH 和普通 Linux 完全一致:端口转发、跳板机、Agent 都能用。
SSH Config(免输地址)
vim ~/.ssh/config
内容示例:
Host work-server
HostName 192.168.1.100
User dev
Port 22
IdentityFile ~/.ssh/id_ed25519
配好后直接 ssh work-server 就能连上。
跳板机连接
Host internal
HostName 10.0.0.50
User deploy
ProxyJump work-server
常见问题
SSH 连接被拒
- 服务器 IP / 端口 / 用户名是否正确
- 公钥是否已加到服务器 authorized_keys
- 如果用密码登录,Ubuntu chroot 的 passwd 登录可能需要额外配置
Git push 失败(HTTPS 方式)
GitHub 2021 年起不再支持密码认证。改用 SSH clone(git clone git@github.com:...)或配置 token:
git config --global credential.helper store
# 下次 push 时输入 token 代替密码
网络问题
Operit 的 chroot 和 Android 宿主共用网络接口,但部分代理(VPN/Shadowrocket 等)可能不影响 chroot 进程。如果 Git clone 或 SSH 超时,先确认 Android 主应用能正常联网。