大网数据广告活动
服务器运维问答

git pull: Permission denied (publickey)

· 52CE 我爱测

So I am trying to get git to work with my repo server (1.2.3.4) (debian) on my new server on AWS (4.5.6.7 / 10.0.0.111). My repo's .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = tru…

问题原文

原帖链接 · chris · CC BY-SA 3.0

So I am trying to get git to work with my repo server (1.2.3.4) (debian) on my new server on AWS (4.5.6.7 / 10.0.0.111).

My repo's .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "origin"]
    url = [email omitted]:/opt/git/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

I'm getting this error:

[ec2-user@ip-10-0-0-111 html]$ sudo git pull
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

My public key is present in /home/git/.ssh/authorized_keys

I previously I was prompted for the password for the user git on my repo server (not my key file passphrase). I then disabled password auth for the git user, and received the permission denied instead. During this time and now with the error above I was able to successfully login via ssh:

ssh [email omitted]

With no password prompt or such:

debug1: Offering RSA public key: /home/ec2-user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).

A successful ssh login on the repo server (1.2.3.4) looks like this in the /var/log/auth.log:

Feb 22 15:45:44 hostname sshd[20142]: Connection from 4.5.6.7 port 50409
Feb 22 15:45:44 hostname sshd[20142]: Found matching RSA key: <fingerprint>
Feb 22 15:45:44 hostname sshd[20142]: Accepted publickey for git from 4.5.6.7 port 50409 ssh2
Feb 22 15:45:44 hostname sshd[20142]: pam_unix(sshd:session): session opened for user git by (uid=0)

When I try git pull this is what auth.log looks like:

Feb 22 15:46:41 hostname sshd[20177]: Connection from 4.5.6.7 port 50410

Then nothing more.

How can I debug the git ssh authentication failure for git when the normal ssh command works perfectly?

已采纳解答

原帖链接 · Jakuje · CC BY-SA 3.0

You do git pull under sudo, which is the problem. Doing only

git pull

will work for you. Also doing

sudo ssh [email omitted]

will fail for you. The problem is that sudo changes user and it does no longer see your identity file /home/ec2-user/.ssh/id_rsa (it searches in /root/.ssh/id_rsa). Do the pull with your normal user or copy/move your key to appropriate location for the target user (root).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。