git私有远程库的建立与使用
来源:互联网 发布:什么是矩阵音响 编辑:程序博客网 时间:2024/04/30 00:00
照着 pro git book来架了个私有git 远程库,做个记录。
验证选用ssh,RSA加密方式。
首先
在远程服务器架设库:
yum install git-core
建好后,就是建一个远程裸库了:
cd /opt mkdir git cd git mkdir yukonProject.git cd yukonProject.git git --bare init
就已经建好裸库了
新建用户
sudo adduser -m yukon12345 passwd yukon12345su yukon12345cd ~mkdir .ssh
设置ssh的公钥
以下2步可以使本地计算机操作时免输入密码
生成RSA 公钥和私钥
首先看看本地电脑有没有现成的秘钥
ls -al ~/.ssh
如果有内容,就不用继续操作了
没有的话
ssh-keygen -t rsa -C "电子邮件地址"
之后一路回车就行。
在 C:/用户/.ssh文件夹里,
会生成id_rsa.pub 和id_rsa等。找到id_rsa.pub,这是公钥
把生成的公钥上传到 user的home目录,
使用 cat id_rsa.pub >> ~/.ssh/authorized_keys
或者复制id_rsa.pub 的内容到.ssh/authorized_keys
这一步为添加信任公钥。
本地的git操作练习
从远程库获取本地库
本地端:
cd d:\gittestgit clone yukon12345@yukon12345.com:/opt/git/yukonProject.git
收到反馈:
Warning: Permanently added 'yukon12345.com,114.215.191.81' (RSA) to the list of known hosts.yukon12345@yukon12345.com's password:warning: You appear to have cloned an empty repository.Checking connectivity... done.
仍然要输入密码?
这里已经把公钥提交到了authorized_keys仍然要输入密码,查了下是由于这个文件不能有所有者之外的写权限。以及.ssh也不能有之外的写权限而默认的authorized_keys 还有个用户组的写权限。
这里去除group的写权限:
su yukon12345cd ~chmod 700 .sshcd .sshchmod 644 authorized_keys
使得文件权限为如下:
-rw-r--r-- 1 yukon12345 yukon12345 400 Mar 3 23:33 authorized_keysdrwxr----- 2 yukon12345 yukon12345 4096 Mar 3 23:33 .ssh
再次使用clone或者pull等时无需密码。
那么就设置成功了。以后就无需输入可以直接操作远程git库。
查看状态
在gittest里会生成已个yukonProject的文件夹。里面有.git的空目录。往目录里加一个hello.txt后: git status
On branch masterInitial commitUntracked files: (use "git add <file>..." to include in what will be committed) hello.txtnothing added to commit but untracked files present (use "git add" to track)
本地库的更新提交
git add .git commit
windows下会聪明的弹出记事本来叫你输入。执行 git log
commit 025369a380e9d1409fbacadb82d2ad56ea245fe6Author: yukon12345 <yukon12345@163.com>Date: Mon Mar 2 22:40:48 2015 +0800 git for new user
执行 git push
来推向远程服务器
Warning: Permanently added 'yukon12345.com,114.215.191.81' (RSA) to the list of known hosts.yukon12345@yukon12345.com's password:Counting objects: 3, done.Writing objects: 100% (3/3), 214 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)error: unpack failed: unpack-objects abnormal exiterror: insufficient permission for adding an object to repository database ./objectsfatal: failed to write objectTo yukon12345@yukon12345.com:/opt/git/yukonProject.git ! [remote rejected] master -> master (n/a (unpacker error))error: failed to push some refs to 'yukon12345@yukon12345.com:/opt/git/yukonProject.git'
无法更新库?
这里出现了报错,看了下是由于权限问题导致的。
ls -altotal 16drwxr-xr-x. 3 root root 4096 Mar 2 22:28 .dr-xr-xr-x. 22 root root 4096 Feb 17 17:27 ..drwxr-xr-x 3 root root 4096 Mar 2 22:29 git
将服务器库的所有者或者所有者组权限修改:
chown -R yukon12345 /opt/gitchgrp yukon12345 /opt/git
再次push后就没有报错了
使用帮助:
如下格式:
git reset --help
这句话在windows下直接弹出帮助的网页。
0 0
- git私有远程库的建立与使用
- 【原创】GIT远程库建立、使用与自动备份
- 建立私有的git服务
- git图形化工具GitKraken的使用——创建远程分支与建立追踪关系
- Cygwin 下建立自己的Git系统 与远程同步
- 使用Gitolite建立远程git仓库
- 建立一个git私有仓库
- Git & Github建立与使用
- 使用git建立远程仓库,让别人git clone下来
- 使用git建立远程仓库,让别人git clone下来
- 使用git建立远程仓库,让别人git clone下来
- 使用git建立远程仓库,让别人git clone下来
- 使用git建立远程仓库,让别人git clone下来
- 使用git建立远程仓库,让别人git clone 下来
- 使用git建立远程仓库,让别人git clone下来
- 使用git建立远程仓库,让别人git clone下来
- CocoaPods本地私有库、远程私有库使用整理
- 使用navicat建立与服务器的远程mysql连接
- 【Unity3D】Unity3D中的C#基本语法知识点①(变量与数组)
- poj3253求切割木板开销最少是多少, 赫夫曼编码
- Duang~ Golang 学习初探
- 3.2学习内容:android图片灰度化,VelocityTracker类
- 图片延迟加载——例子
- git私有远程库的建立与使用
- java BTrace-代码追踪
- STL vector使用
- STL求最长上升子序列
- CodeForces 25C Roads in Berland(图论-最短路径)
- c#基础(四)----运算符
- emacs配置详解及C/C++IDE全功能配置演示(附配置文件)
- 黑马程序员——Java基础---反射机制
- IOS开发获得当前手机的网络状态