赞
踩
git init --bare
选项创建裸仓,避免不必要push冲突;git config receive.denyCurrentBranch ignore
;不建议打开,防止混乱,可创建新分支进行管理;# 假设当前用户为GitTest, 当前路径为/home/GitTest,当前公网ip为13.130.130.8
mkdir test.git # 创建.git结尾文件夹
cd ./test.git
git init --bare # 文件夹内初始化仓库;
vim README.md # 创建第一个文件
git add . && git commit -m "init" # 第一次提交
git remote add origin ssh://GitTest@13.130.130.8/home/GitTest/test.git # 创建远程仓库
git push origin master # 将本项目提交至远程仓库
C:\user\.ssh\id_rsa.pub
文件,将其内容copy至服务端GitTest用户目录/home/GitTest/.ssh/authorized_keys
文件(第一次使用需手动创建); # 输入密码后成功操作
git clone ssh://GitTest@13.130.130.8/home/GitTest/test.git
git checkout -b Leran_Note # 创建本地分支
git push origin Leran_Note:Leran_Note # 推送至远程仓,并关联远程分支
上述操作后,GitTest用户仍可通过ssh直接访问,进行/home/GitTest目录下文件操作,多人使用时仓库文件安全性无法保证,需进行权限管理。
cat /etc/passwd
可看到 GitTest:x:1000:1000:GitTest,,,:/home/GitTest:/bin/bash
,即GitTest用户通过ssh链接后自启动一个/bin/bash类型shell,若想禁止其通过ssh直接登录,需更换自启动shell;git-shell
的登陆 shell,一般情况下位于 /usr/bin/git-shell
,可做到仅允许git相关操作;chsh GitTest
,然后将shell路径更改为/usr/bin/git-shell
,完成替换;ssh GitTest@13.130.130.8 Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-164-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage New release '22.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it. Welcome to Alibaba Cloud Elastic Compute Service ! Last login: Sat Nov 18 00:09:50 2023 from 127.0.0.1 fatal: Interactive git shell is not enabled. hint: ~/git-shell-commands should exist and have read and execute access. Connection to 13.130.130.8 closed.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。