ubuntu 16.04
总结一下git服务器的搭建的过程:按照此方法搭建亲测OK
服务器端:
- sudo apt-get install git openssh-server openssh-client
- apt-get install git
- sudo adduser git
- 切换到 git用户,su git
- mkdir /home/git/.ssh
- cd /home/git/.ssh; touch authorized_keys
- 把客户端第4步查看到的公钥写到 authorized_keys 文件中,一个公钥一行
- git的家目录下创建一个文件夹,例如:mkdir /home/git/code
- cd /home/git/code; git init --bare sample.git 创建一个叫sample的远程库
- ifconfig 查看网络地址,例如:192.168.1.188, 那么你的远程库就是:
git@192.168.1.188:/home/git/code/sample.git
客户端:
例如现在你是wyz用户:
- sudo apt-get install git
- ssh-keygen -C “your@email.com”, 例如:ssh-keygen -C “867439374@qq.com”
- 在 /home/wyz/.ssh 中就会生成私钥和公钥
- cat /home/wyz/.ssh/id_rsa.pub 查看公钥
- 找一个目录创建文件夹,例如:mkdir /home/wyz/git_test
- cd /home/wyz/git_test; git init
- touch hello.c; git add .; git commit -m “add hello.c file”
- 建立和远程仓库的连接:
git remote add origin git@192.168.1.150:/home/git/code/sample.git - 第一次上传到远程仓库:
git push -u origin master - 以后每次上传到远程仓库:
git push