在Mac系统中搭建Git服务器,实现免密码操作,可以让我们更方便地进行代码的提交和更新,本文将详细介绍如何在Mac系统中搭建Git服务器,并实现免密码操作。
安装Git
我们需要在Mac系统中安装Git,可以通过以下两种方式进行安装:
1、使用Homebrew安装:
brew install git
2、从官网下载安装包进行安装:
访问Git官网(https://git-scm.com/),下载适合Mac系统的安装包,然后按照提示进行安装。
创建Git用户
为了实现免密码操作,我们需要创建一个Git用户,打开终端,输入以下命令:
sudo dscl . -create /Users/git sudo passwd git
按照提示设置Git用户的密码。
创建Git仓库
在Git用户的主目录下,创建一个用于存放代码的文件夹,my_project
,然后进入该文件夹,初始化一个新的Git仓库:
cd ~/my_project git init
配置SSH密钥
为了让其他用户能够通过SSH免密码访问你的Git仓库,你需要生成一对SSH密钥,在终端中输入以下命令:
ssh-keygen -t rsa -C "your_email@example.com"
按照提示操作,会生成两个文件:id_rsa
(私钥)和id_rsa.pub
(公钥),将公钥内容复制到Git服务器的~/.ssh/authorized_keys
文件中,你可以使用以下命令将公钥内容复制到剪贴板:
pbcopy < ~/.ssh/id_rsa.pub
配置Git服务器
接下来,我们需要配置Git服务器,打开~/my_project/config
文件,添加以下内容:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@localhost:my_project.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
这里的url
需要替换为你的实际Git服务器地址,保存并关闭文件。
启动Git服务
我们需要启动Git服务,在终端中输入以下命令:
git daemon --base-path=. --export-all --enable=receive-pack --enable=upload-pack --reuseaddr --verbose --user=git --group=git --daemonize --export-all --enable=receive-pack --enable=upload-pack --reuseaddr --verbose --user=git --group=git --pid=/var/run/gitd.pid --work-tree=~/my_project --no-port-forwarding --authentication=publickey --ssh-command="ssh -i /Users/git/.ssh/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -F /dev/null" & disown -a && exec git-daemon --help "$@" --export-all --enable=receive-pack --enable=upload-pack --reuseaddr --verbose --user=git --group=git --daemonize --export-all --enable=receive-pack --enable=upload-pack --reuseaddr --verbose --user=git --group=git --pid=/var/run/gitd.pid --work-tree=~/my_project --no-port-forwarding --authentication=publickey --ssh-command="ssh -i /Users/git/.ssh/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -F /dev/null" & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown -a && exec git-daemon --help "$@" &> /dev/null & disown-a && exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? || exit $? && echo "Failed to start GIT on port ${GIT_PORT}" >> "/Library/Logs/GitDaemon.log" && killall caddy && killall caddy; nohup_append true; setuidgid git www; setgid www; chdir /usr/local/var; gosu www bundle update; gosus www bin/caddy start –conf="/usr/local/etc/caddyfile"; gosu www bundle install; gosu www bin/caddy restart > "/Library/Logs/GitDaemon.log"; nohup_append true; setuidgid www; setgid www; chdir "/usr"; gosu www bundle update; gosus www bin/caddy start –conf="/usr/local/etc/caddyfile"; gosu www bundle install; gosu www bin/caddy restart > "/Librarybroke here, but it'll work if you run the command in one line." EOF chmod +x ~/my_project Make
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/376215.html