已 clone 的 git,如何为其设置有效用户

2014-08-08 19:06:57 +08:00
 konakona
其实这个问题发生在我服务器上,很早以前是用git clone http://xxxx.github.com/xxxx 建立的版本,随后服务器上随着程序的自动升级,已经产生了不少的文件变化。现在需要push,然后在本机开发环境中进行大量的插件开发工作。

此时才发现,clone的时候忘了加username,所以提交的时候会说:Access denied.
fatal: The remote end hung up unexpectedly

现在怎么样实现git clone http://username:xxx.github.com/xxx 的效果呢?
7721 次点击
所在节点    程序员
19 条回复
raptium
2014-08-08 19:15:09 +08:00
git remote set-url origin ....
konakona
2014-08-08 19:26:33 +08:00
@raptium

[root@li671-193 CRAZYPHPER.COM]# git config user.name 'konakona'
[root@li671-193 CRAZYPHPER.COM]# git config user.email 'iloveav@vip.qq.com'

[root@li671-193 CRAZYPHPER.COM]# git push
git@github.com's password:

它现在让我输入git的帐号密码呢,我木有~
kchum
2014-08-08 19:49:15 +08:00
看不懂什么意思…
dorentus
2014-08-08 19:56:38 +08:00
git remote set-url origin git@github.com:xxxx/xxx.git
dorentus
2014-08-08 20:00:10 +08:00
git config 设置的名字和 email 只是用在 commit 信息里面的,和权限什么无关。

github 提供的两种 repo URL,https 的和 ssh 的,其中 https 的无论是加了用户名的还是不加用户名的,push 的时候都需要提供用户名和密码(不过似乎可以设置保存在本地什么地方)。ssh 的那种,在设置好 ssh public key 验证的情况下(1),push 和 pull 都不再会要输密码。

注1) https://github.com/settings/ssh
konakona
2014-08-08 20:55:41 +08:00
@dorentus 我是这样做的。
akfish
2014-08-08 22:18:55 +08:00
你对你clone的那个repo有所有权没,没有你当然不能push。
lijinma
2014-08-08 23:00:46 +08:00
这种问题描述有种想摔电脑的冲动。

1. 你服务器 clone 了谁的 repo?

2. 你本机 clone 了谁的 repo?

3. 你是从本机 push 到 GitHub 上还是要 push 到服务器上?

讲问题讲清楚点啊。。

你如果 clone 了“别人”的代码而不是 clone 了自己 fork 的“别人”的代码,除非“别人”允许你 push 代码,否则你没有push的权限。

你如果要从你本机 push 到你自己的服务器,需要你自己 git remote add 你服务器的repo。
GhostFlying
2014-08-08 23:27:45 +08:00
github的话,如果你有对应repo的管理权限,简单的做法是找到你本地git的ssh(一般在~/.ssh),把pub_key的内容复制到你的github帐号里或者repo的设置里,然后直接push 到ssh地址就好了。

如果你没有repo的管理权限,基本免谈,当然你可以重新fork一个,push到自己fork的那个repo,然后merge + pull request
konakona
2014-08-09 01:46:52 +08:00
@lijinma 怎么可能会是你的这种疑惑...根本没有这些问题。
我描述得听清楚的啊,都是自己的版本,只不过服务器用的是 git clone 没有加帐号名称,现在服务器因为装了很多插件,想要上传到git,然后我本机下下来开发环境中再调整。 就这样咯...
GhostFlying
2014-08-09 02:09:47 +08:00
@konakona git clone的时候都是不加用户信息的吧,都是在提交的时候才检查用户
konakona
2014-08-09 02:44:14 +08:00
@GhostFlying 所以,你再看看我第二楼的问题。git不是我的帐号,是git平台默认的。它没有询问我我的帐号是多少,我也没有找到我应该在哪儿设置。u know? ssh公钥什么的早就设置弄好了,不然我也不能够用得了我的git(因为是私有项目)..
ivenvd
2014-08-09 03:19:06 +08:00
@konakona 四楼五楼已经说得很清楚了。你自己对问题的理解有问题,github 不认帐号,只认 key。你 Push 不了不是因为账号不对,也不是因为 key 不对,而是因为 url 不对。
thuai
2014-08-11 09:34:11 +08:00
先 ssh -T 下看账号的key对么?
konakona
2014-08-12 02:50:10 +08:00
@ivenvd url是对的。我的是私有库。
konakona
2014-08-12 03:03:16 +08:00
@ivenvd
[root@li671-193 CRAZYPHPER.COM]# ssh -T git@git.oschina.net
git@git.oschina.net's password:
Permission denied, please try again.

以前都是这样设置key的,今天就不得了。唉.........我配了几十个git了,今天第一次遇到这样的事情。
konakona
2014-08-12 03:08:02 +08:00
[root@li671-193 CRAZYPHPER.COM]# ssh -vT git@oschina.net
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to oschina.net [61.145.122.155] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8
debug1: match: OpenSSH_5.8 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host 'oschina.net (61.145.122.155)' can't be established.
RSA key fingerprint is eb:2a:c2:28:63:43:71:d2:1c:da:6b:ff:c9:85:ff:54.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oschina.net,61.145.122.155' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
konakona
2014-08-12 03:30:06 +08:00
我直接把.git 删了,在原项目目录上执行了如下代码:


[root@li671-193 CRAZYPHPER.COM]# git config --global user.name "konakona"
[root@li671-193 CRAZYPHPER.COM]# git config --global user.email "iloveav@vip.qq.com"
[root@li671-193 CRAZYPHPER.COM]# git clone git@git.oschina.net:konakona/CRAZYPHPER.COM.git
Initialized empty Git repository in /opt/lampp/htdocs/CRAZYPHPER.COM/CRAZYPHPER.COM/.git/
git@git.oschina.net's password:
Permission denied, please try again.
git@git.oschina.net's password:
Permission denied, please try again.
git@git.oschina.net's password:
konakona
2014-08-12 03:30:33 +08:00
=.= 公钥已添加,完全没有问题啊...
就是说我密码不对。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/126836

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX