当前位置:   article > 正文

linux搭建git仓库_linux创建git仓库

linux创建git仓库

git安装与配置

# git安装
yum install -y git

# git配置(以下为root用户下配置)
# 添加git组
groupadd git

# 添加账号、密码(账号zdtest可根据自己需求修改)
useradd zdtest -g git
passwd zdtest
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

创建远程仓库(linux端)

  • 创建个人文件夹
mkdir -p /home/data/zdtest

cd /home/data/zdtest
  • 1
  • 2
  • 3
  • 创建远程仓库文件夹
mkdir -p zdtest.git
  • 1
  • 初始化远程仓库
git init --bare zdtest.git
  • 1
  • 仓库配置
chown -R zdtest:git zdtest.git/
  • 1

远程仓库访问(windows端)

  • 使用git bash进行仓库连接
# 格式:用户名@linux端ip:git路径
# 用户名使用步骤一中创建的用户
git clone zdtest@192.168.1.10:/home/data/zdtest/zdtest.git
  • 1
  • 2
  • 3
  • 本地文件上传(push)

    • 方式1:使用TortoiseGit界面版软件上传(暂不介绍);
    • 方式2:命令行方式上传;
    # 初始化仓库
    git init
    
    # 连接远程仓库
    git remote add origin zdtest@192.168.1.10:/home/data/zdtest/zdtest.git
    
    # 将文件提交至缓存区
    git add .
    
    # 提交commit信息
    git commit -m 'upload files'
    
    # 代码推送
    git push origin master
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

公钥配置

windows端

  • 更新配置信息(在git bash内操作)
# 配置用户名(用户名自行定义)
git config --global user.name 'zdtest'

# 配置邮箱(邮箱自行定义)
git config --global user.email 'zdtest@xx.com'

# 信息查看
git config --list
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 删除旧的ssh信息(删除路径C:\Users\guanzedong\.ssh文件夹内所有文件)
  • 生成新的私钥(id_rsa)和公钥(id_rsa.pub)
# zdtest@xx.com为git config时配置的邮箱
ssh-keygen -t rsa -C "zdtest@xx.com"

# 配置过程中一直回车即可
  • 1
  • 2
  • 3
  • 4
  • 拷贝id_rsa.pub中的内容

linux端

  • 修改sshd配置
vim /etc/ssh/sshd_config

# 编辑如下:
RSAAuthentication yes # 有些版本没有该配置
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 重启sshd
  • 创建公钥文件
# 进入用户目录
cd /home/zdtest

# 创建.ssh文件夹和authorized_keys文件
mkdir .ssh
chmod 755 .ssh
cd .ssh
touch authorized_keys
chmod 755 authorized_keys
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 将windows中id_rsa.pub内容拷贝至authorized_keys文件
  • 权限修改
chown zdtest:git .ssh
chown zdtest:git .ssh/authorized_keys
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/164129?site
推荐阅读
相关标签
  

闽ICP备14008679号