首页 > 代码库 > debian多用户下github git push的配置, 不需要帐号密码.

debian多用户下github git push的配置, 不需要帐号密码.

因为debian有多种用户, root和普通的user

所以我把user作为了私有的git仓库用户. 把root超级管理员作为了github的用户.

这样子只需要单独配置两个不同的共用gitconfig就可以通用了.

第一个是root下的配置, 在/root/.gitconfig

[user]
    name = rainysia
    email = rainysia@gmail.com
[alias]
    co = checkout
    br = branch
    ci = commit
    st = status
    last = log -1 HEAD
    cf = config
    md = commit --amend
    dt = difftool
    mt = mergetool
    line = log --oneline
    latest = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) [%(committername)]'
    ls = log --pretty=format:\"%C(yellow)%h %C(blue)%ad %C(red)%d %C(reset)%s %C(green)[%cn]\" --decorate --date=short
    hist = log --pretty=format:\"%C(yellow)%h %C(red)%d %C(reset)%s %C(green)[%an] %C(blue)%ad\" --topo-order --graph --date=short
    type = cat-file -t
    dump = cat-file -p
[color]
    diff = auto
    status = auto
    branch = auto
[http]
	sslverify = true
[https]
	sslverify = true


第二个是/home/tom/.gitconfig

[user]
	name = tom xia
	email = tomx@***.com
[alias]
	co = checkout
	br = branch
	ci = commit
	st = status
	last = log -1 HEAD
    cf = config
    md = commit --amend
    dt = difftool
    mt = mergetool
    line = log --oneline
    latest = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) [%(committername)]'
    ls = log --pretty=format:\"%C(yellow)%h %C(blue)%ad %C(red)%d %C(reset)%s %C(green)[%cn]\" --decorate --date=short
    hist = log --pretty=format:\"%C(yellow)%h %C(red)%d %C(reset)%s %C(green)[%an] %C(blue)%ad\" --topo-order --graph --date=short
    type = cat-file -t
    dump = cat-file -p
[color]
	diff = auto
	status = auto
	branch = auto


这里只说下github在root下的.

#cd ~/.ssh
#ssh-keygen -t rsa -C "username@yourhost"

一直回车ok,也可以自己换地方保存, username就是你的github的用户名了,yourhost就是你注册的邮箱了.比如我的rainysia@gmail.com

#cat ~/.ssh/id_rsa.pub  | ssh username@yourhost `cat >> .ssh/authorized_keys`     ssh username@yourhost

登陆github系统。点击右上角的 Account Settings--->SSH Public keys ---> add another public keys

把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了
接着打开git ,测试连接是否成功

#ssh -T git@github.com
如果提示:Hi xxxx! You‘ve successfully authenticated, but GitHub does not provide shell access. 说明你连接成功了

接下来git clone 自己的代码.

克隆完修改, push的时候会提示输入用户名和密码.我们暂停这一操作

在项目目录去修改下,把下面的username换成你的,project_name就是你的github的项目名

#git remote set-url origin git@github.com:username/project_name

 或者直接修改项目下.git/config里 [remote "origin"] 的url为 url = git@github.com:username/project_name

这样就可以直接git push了.



debian多用户下github git push的配置, 不需要帐号密码.