iPhone免越狱Git服务器搭建教程-iSH

需求

● 需要一个保存数据的仓库
● 仓库可在不同地方上传/同步数据
● 仓库安全性高些
● 仓库费用低些
● 仓库随处可用
● 仓库迁移容易些
● 更新时, 步骤方便
iPhone免越狱Git服务器, 能完美解决上述需求. 人与Git服务器同在, 随时可更新笔记/项目代码, 无需收费, 需要时开启服务器即可, 更换iPhone手机时, 手机自带迁移数据也能把Git服务器数据一起迁移.

问题汇总

iSH Git服务器使用问题汇总

效果

点击4次即可更新提交修改
在这里插入图片描述

实现

安装 iSH app

AppStore 搜索 iSH 下载在这里插入图片描述

1. iSH 安装及ssh功能启用

1.1 iSH安装

apk add neofetch openssh neovim git

1.2 设置SSH root 密码

ssh-keygen -A
passwd
此处输入root密码(123456)

1.3 打开root用户登录ssh权限

echo ‘PermitRootLogin yes’ >> /etc/ssh/sshd_config

1.4 启用 sshd

/usr/sbin/sshd

2. CMD命令窗口

2.1 远程SSH连接iSH

ssh root@手机ip(如: ssh root@192.168.1.129) // 电脑ip需要同一个网段, 如192.168.1.x
输入root密码(123456)

2.2 创建project.git仓库, 电脑cmd终端:

    iPhone:~# pwd                               		// 查看路径
    /root 
    iPhone:~# 
    iPhone:~# mkdir project.git                    		// 创建文件夹
    iPhone:~# ls
    iPhone:~# cd project.git/                      		// 进入文件夹
    iPhone:~# git --bare init                      		// 初始化仓库
    // 路径 /private/var/root/project.git/
    Initialized empty Git repository in /private/var/root/project.git/      

3. Git 终端

3.1 clone project.git:

git clone ssh://root@192.168.2.129/root/project.git

4. git config配置

● 在 project/.git/config 文件中添加:
[remote "iphone"]
url = ssh://root@192.168.1.184/root/projects/notes/notes.git
fetch = +refs/heads/*:refs/remotes/iphone/*

5. iphone_git.bat 批处理文件

git pull iphone master
git add .       
git commit -m "iphone"
git push iphone master
::保留cmd窗口
pause   

5. 免密配置

5.1 PC生成公钥秘钥

命令提示符窗口输入:

ssh-keygen -t rsa // 一直回车
C:\Users\Administrator.ssh\ 目录将生成两个文件:
C:\Users\Administrator.ssh\id_rsa // 私钥
C:\Users\Administrator.ssh\id_rsa.pub // 公钥

5.2 iPhone文件权限设置

命令提示符窗口输入:
ssh root@手机ip(如: ssh root@192.168.1.129)
输入root密码(123456)
// cd到手机 .ssh目录, 如目录不存在, 则新建 .ssh目录
iPhone:~# cd ~/.ssh
-ash: cd: can't cd to /root/.ssh: No such file or directory            
iPhone:~# mkdir .ssh
// 进入 .ssh 目录
iPhone:~# cd .ssh
// 给目录及文件授权
iPhone:~/.ssh# touch authorized_keys
iPhone:~/.ssh# ls
authorized_keys
iPhone:~/.ssh# chmod 700 ~/.ssh
iPhone:~/.ssh# chmod 600 ~/.ssh/authorized_keys

iPhone:~/.ssh# ls
authorized_keys  id_rsa.pub
iPhone:~/.ssh# cat id_rsa.pub >> ~/.ssh/authorized_keys

5.3 复制公钥文件到 iphone:

window → cmd → scp C:\Users\Administrator\.ssh\id_rsa.pub root@192.168.1.49:/root/.ssh
password:

5.4 iPhone 添加公钥:

window → cmd → ssh root@192.168.1.129
password:
iPhone: cd ~/.ssh
iPhone: cat id_rsa.pub >> ~/.ssh/authorized_keys

5.5 后面用命令行访问即可不用密码

问题汇总:

问题: Permission denied, please try again.

● 原因: 
iSH app 复制黏贴执行的的 echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config 有时候会写入失败.
● 解决:
方式1. iSH app 手动输入:
	echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
	重启App.
方式2. iSH app 手动cd到目录ssh, 然后手动输入:
	echo 'PermitRootLogin yes' >> sshd_config   
	重启App.

问题: ssh: connect to host 192.168.2.129 port 22: Connection refused

    手机ip地址填错了.

问题: push代码时, 老是卡在 remote: Resolving deltas: 5% (166/3087)

● 解决: 
在 iPhone SSH 终端运行:
    > git config --global pack.threads "1"

github ishapp-issues

问题: git pull iphone 时, 报错 fatal: unable to access ‘http://192.168.1.129/root/projects/notes/notes.git/’:

git bash:
    fatal: unable to access 'http://192.168.1.129/root/projects/notes/notes.git/': 
    Failed to connect to 192.168.1.129 port 80: Connection refused
● 原因:
     ssh 的链接填错导致
● 解决:
    .git/config → 修改 iphone 的url 为:
        [remote "iphone"]
            url = ssh://root@192.168.1.129/root/projects/notes/notes.git
            fetch = +refs/heads/*:refs/remotes/iphone/* 

问题: 输入命令: git pull iphone

root@192.168.1.49's password:
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 44 (delta 26), reused 29 (delta 12), pack-reused 0
Unpacking objects: 100% (44/44), done.
From ssh://192.168.1.49/root/projects/notes/notes
* [new branch]      master     -> iphone/master
You asked to pull from the remote 'iphone', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
● 解决:
    命令修改为: 
        git pull iphone master 

问题: REMOTE HOST IDENTIFICATION HAS CHANGED!

由于PC里保存着iphone的ssh信息, 需要清除后, 才能输入密码:
    ssh-keygen -R 192.168.1.129      // 192.168.1.129 为手机的ip

问题: fatal: ‘/root/projects/company/rope.git’ does not appear to be a git repository

git.exe clone --progress -v "ssh://root@192.168.1.49/root/projects/company/rope.git" 
"D:\012-Git\_20210317git\company\rope"
Cloning into 'D:\012-Git\_20210317git\company\rope'...
fatal: '/root/projects/company/rope.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
git did not exit cleanly (exit code 128) (11000 ms @ 2022/2/16 23:33:26)
● 解决:
    Git服务器的目录名取错了, company 目录取成 compony, 在服务器中修改过来就可以了
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值