当前位置:   article > 正文

ubuntu下面的git服务器搭建_user 'git' already exists

user 'git' already exists

1、安装相应的软件和依赖


ubuntu:~$ sudo apt-get install git-core openssh-server openssh-client
git-core是git版本控制核心软件

安装openssh-server和openssh-client是由于git需要通过ssh协议来在服务器与客户端之间传输文件

然后中间有个确认操作,输入Y后等待系统自动从镜像服务器中下载软件安装,安装完后会回到用户当前目录。如果

安装提示失败,可能是因为系统软件库的索引文件太旧了,先更新一下就可以了,更新命令如下:

ubuntu:~$ sudo apt-get update

更新完软件库索引后继续执行上面的安装命令即可。

2、配置服务器

在服务器端

查看ssh有没有启动

  1. root@weiqifa-Inspiron-3847:/home/git# ps -e|grep ssh
  2. 1686 ? 00:00:00 sshd
  3. root@weiqifa-Inspiron-3847:/home/git#

创建git用户,用来管理代码的用户

  1. root@weiqifa-Inspiron-3847:/home/git# sudo useradd git
  2. useradd: user 'git' already exists
  3. root@weiqifa-Inspiron-3847:/home/git#

秘钥文件

在gitServer上我们首先查看/home/git/.ssh目录下是否存在authorized_kesys文件,

如果没有,可以通过touch authorized_keys创建此文件。


在客户机端

在客户端用ssh-keygen -t rsa 生成秘钥

然后用命令scp把秘钥复制到服务器

scp id_rsa.pub weiqifa@192.168.0.88:/home/git/.ssh/

然后回到服务器

  1. root@weiqifa-Inspiron-3847:/home/git/.ssh# ls
  2. authorized_keys id_rsa.pub
  3. root@weiqifa-Inspiron-3847:/home/git/.ssh# cat id_rsa.pub >> authorized_keys
  4. root@weiqifa-Inspiron-3847:/home/git/.ssh# cat authorized_keys
  5. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkIt2Hh532FoWoj0IUztIYF+jz4F1KvyOAmrhpxUMnnuj+YEOhyw6AGL/NAjmE5r8SzeJLTtAkVk9s143R9tYouPOgHPuwTTFvDy/skjD14yMne1aHzre2rM0jGiv5gtZDmi523FvQob7oTM5xOKKk3lsMBQNPdWrPPWqs8kS941sdWYymNQqFLBH4DpzDUAS+Itk5U6aNvVcQbldmGR+F3IxIKxH76HwpTmh+Os5fqraQLOMpWZzu8h0KMMMnNdideV0lHfq40Swb0ZO6ZGy/tdXBTc7oO8bn11oRVQ+Uf+USYMBzB6PCe6gODI3Fp0cBFzzQNque6MIAh6ELClUn Administrator@JU674J315CAOGPV
  6. root@weiqifa-Inspiron-3847:/home/git/.ssh#


3、建立仓库并克隆
建立个文件夹用来管理仓库

  1. root@weiqifa-Inspiron-3847:/home/git# mkdir repo
  2. root@weiqifa-Inspiron-3847:/home/git# chown -R git:git repo/
  3. root@weiqifa-Inspiron-3847:/home/git# chmod 700 repo/
  4. root@weiqifa-Inspiron-3847:/home/git#

在服务器测试clone一下

  1. root@weiqifa-Inspiron-3847:/home/git# cd repo/
  2. root@weiqifa-Inspiron-3847:/home/git/repo# git init --bare sscom.git
  3. Initialized empty Git repository in /home/git/repo/sscom.git/
  4. root@weiqifa-Inspiron-3847:/home/git/repo# cd ../
  5. root@weiqifa-Inspiron-3847:/home/git# ls
  6. bin examples.desktop gitosis id_rsa.pub repo
  7. root@weiqifa-Inspiron-3847:/home/git# cd ../
  8. root@weiqifa-Inspiron-3847:/home# git clone --bare git
  9. git/ gitrepository/
  10. root@weiqifa-Inspiron-3847:/home# git clone --bare git/repo/sscom.git/
  11. Cloning into bare repository 'sscom.git'...
  12. warning: You appear to have cloned an empty repository.
  13. done.
  14. root@weiqifa-Inspiron-3847:/home# ls
  15. git gitrepository lost+found sscom.git weiqifa
  16. root@weiqifa-Inspiron-3847:/home#



在客户端clone一下

  1. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh
  2. $ git clone git@192.168.0.88:/home/git/repo/sscom.git
  3. Cloning into 'sscom'...
  4. git@192.168.0.88's password:
  5. warning: You appear to have cloned an empty repository.
  6. Checking connectivity... done.

在客户端push 一下

  1. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh
  2. $ git clone git@192.168.0.88:/home/git/repo/sscom.git
  3. Cloning into 'sscom'...
  4. git@192.168.0.88's password:
  5. warning: You appear to have cloned an empty repository.
  6. Checking connectivity... done.
  7. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh
  8. $ ls
  9. id_rsa id_rsa.pub known_hosts sample/ sscom/
  10. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh
  11. $ cd sscom/
  12. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  13. $ ^C
  14. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  15. $ ls
  16. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  17. $ pwd
  18. /c/Users/Administrator/.ssh/sscom
  19. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  20. $ git branch
  21. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  22. $ echo "this beginnings of project1" > any.file
  23. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  24. $ git add .
  25. warning: LF will be replaced by CRLF in any.file.
  26. The file will have its original line endings in your working directory.
  27. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  28. $ git commit -m "init"
  29. [master (root-commit) e9565b2] init
  30. warning: LF will be replaced by CRLF in any.file.
  31. The file will have its original line endings in your working directory.
  32. 1 file changed, 1 insertion(+)
  33. create mode 100644 any.file
  34. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  35. $ git push origin master
  36. git@192.168.0.88's password:
  37. Counting objects: 3, done.
  38. Writing objects: 100% (3/3), 229 bytes | 0 bytes/s, done.
  39. Total 3 (delta 0), reused 0 (delta 0)
  40. remote: error: insufficient permission for adding an object to repository database ./objects
  41. remote: fatal: failed to write object
  42. error: unpack failed: unpack-objects abnormal exit
  43. To git@192.168.0.88:/home/git/repo/sscom.git
  44. ! [remote rejected] master -> master (unpacker error)
  45. error: failed to push some refs to 'git@192.168.0.88:/home/git/repo/sscom.git'

这个错误查看了一下这个链接

http://blog.csdn.net/yujunf/article/details/7595231

在服务器然后再修改一下

  1. root@weiqifa-Inspiron-3847:/home/git/repo# ls
  2. sscom.git
  3. root@weiqifa-Inspiron-3847:/home/git/repo# chown -R git:git sscom.git/
  4. root@weiqifa-Inspiron-3847:/home/git/repo#

回到客户端再push一下

  1. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)
  2. $ git push
  3. git@192.168.0.88's password:
  4. Counting objects: 3, done.
  5. Writing objects: 100% (3/3), 229 bytes | 0 bytes/s, done.
  6. Total 3 (delta 0), reused 0 (delta 0)
  7. To git@192.168.0.88:/home/git/repo/sscom.git
  8. * [new branch] master -> master
  9. Administrator@JU674J315CAOGPV MINGW64 ~/.ssh/sscom (master)

4、总结

1、原理问题查清楚,哪步在哪里执行,要搞清楚

2、认真仔细,ubuntu对用户权限要求比较高,要特别注意一下

3、学会在网查资料


参考资料:

http://www.linuxdiyf.com/linux/12685.html

https://hacpai.com/article/1445337139234

http://www.linuxdiyf.com/linux/12159.html

http://www.linuxdiyf.com/linux/10730.html

http://www.gitguys.com/topics/creating-a-shared-repository-users-sharing-the-repository/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/572070
推荐阅读
相关标签
  

闽ICP备14008679号