为何无法用普通用户使用github?

查看:150
本文介绍了为何无法用普通用户使用github?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

用root用户,可以成功免密码使用git进行push pull了。
新的项目名称:newstart。
下面是root user的设置。

su root
ssh-keygen -t rsa -f /root/.ssh/id_rsa.github -P ''

将id_rsa.github.pub 粘帖到 ssh key 的githhub web page.

git config --global user.name "someone"
git config --global user.email  "sbd@gmail.com"
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git
ssh -T git@github.com
git clone  git+ssh://git@github.com/someone/newstart.git /tmp/newstart

Cloning into '/tmp/newstart'...

root user可以成功使用,一点问题没有。

现在对一个普通用户debian8 进行设置,刚才的设置全部重新设置了。

su debian8
ssh-keygen -t rsa -f /home/debian8/.ssh/id_rsa.github -P ''

这个key id_rsa.github.pub 粘帖到 ssh key in githhub web page.

git config --global user.name "someone"
git config --global user.email  "sbd@gmail.com"
git config remote.origin.url git+ssh://git@github.com/someone/newstart.git
#注意,在普通用户下,无法使用config.
error: could not lock config file .git/config: Permission denied
sudo git config remote.origin.url git+ssh://git@github.com/someone/newstart.git   
ssh -T git@github.com
Permission denied (publickey).
我通过-i 参数,可以让这个普通用户连接上github.
ssh -i ./id_rsa.github.pub  -vT git@github.com
You've successfully authenticated, but GitHub does not provide shell access.
可惜,连接上没有用,无法clone.

git clone  git+ssh://git@github.com/someone/newstart.git /tmp/newstart
Cloning into '/tmp/newstart'...
Permission denied (publickey).
fatal: Could not read from remote repository.
 Please make sure you have the correct access rights  and the repository exists.

请问,如何针对普通用户,对我的步骤进行修改?什么原因导致这样的事情发生?

解决方案

建议检查一下你的HOME环境变量,可能是你之前修改过它,导致git找不到.gitconfig了;另外,你可以检查一下你的用户主目录下有没有.gitconfig,在你的用户目录下使用:

ls -a | grep .gitconfig

如果显示没有.gitconfig,说明很可能是因为git在当前用户的主目录下找不到gitconfig

或者你可以用locate命令搜索一下.gitconfig

locate .gitconfig

如果很不幸,你用locate没搜到的话,那就使用updatedb更新下locate数据库吧,如果你的硬盘速度够快的话,可以很快就完成。

sudo updatedb

当然用find命令也可以,但是速度比较慢:

sudo find / -name .gitconfig

上述操作有结果后,你看一下.gitconfig文件的所在路径是否是echo $HOME的结果,如果不是,说明的确是你的$HOME环境变量的问题,建议将其重新设置成你的当前用户主目录的路径。

这篇关于为何无法用普通用户使用github?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆