Linux Git SSH 密钥授权失败
Posted
技术标签:
【中文标题】Linux Git SSH 密钥授权失败【英文标题】:Linux Git SSH key authorization fail 【发布时间】:2018-11-18 12:23:50 【问题描述】:我在数字海洋上制作了 git 服务器并且工作正常,但我想将授权从密码更改为 SSH 密钥。
现在它在这个服务器和我的 pi 上都可以很好地用于 SSH/SFTP。但是git不想合作。
我有:
/home/git/.ssh
权限 700
/home/git/.ssh/authorized_keys
644
git 的外壳:/usr/bin/git-shell
在本地机器上设置.ssh/config
从加密的随身碟加载私钥
isaac@Isaac-Debian:~$ ssh -vT server
OpenSSH_7.4p1 Debian-10+deb9u3, OpenSSL 1.0.2l 25 May 2017
debug1: Reading configuration data /home/isaac/.ssh/config
debug1: /home/isaac/.ssh/config line 1: Applying options for git-server1.iofist.de
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to serwer ******** port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/isaac/secret/server1git type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/isaac/secret/server1git-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Debian-10+deb9u2
debug1: match: OpenSSH_7.4p1 Debian-10+deb9u2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to server:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:LyaAW9P8EIqkyuf/lEuEIKWTTeu2/3XbOyxx8TmPXa8
debug1: Host 'server1.iofist.de' is known and matches the ECDSA host key.
debug1: Found key in /home/isaac/.ssh/known_hosts:3
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/isaac/secret/server1git
Enter passphrase for key '/home/isaac/secret/server1git':
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
【问题讨论】:
你能从本地主机 ssh 到 git@server 吗?如果不是——问题不在于 git,而在于 ssh。如果是 - 究竟是什么错误?尝试使用GIT_TRACE=1 git $command
进行调试。
我认为这与 shell 有关,但我不想将此帐户仅授予 Git 对 SSH 的访问权限,密码自动旋转 shell 何时工作 /usr/bin/git-shell
我添加了ssh -vT
日志
你知道哪种外壳可以这样工作
Permission denied (publickey). — 这是 ssh 问题,不是 git 问题。
【参考方案1】:
debug1: Trying private key: /home/isaac/secret/server1git Enter passphrase for key '/home/isaac/secret/server1git': debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. Permission denied (publickey).
起初它仍然希望你拥有公钥,所以你也必须创建它。其次,确保您以 root 身份运行 ssh
。它将解决与Permission denied (publickey)
的冲突。
【讨论】:
以上是关于Linux Git SSH 密钥授权失败的主要内容,如果未能解决你的问题,请参考以下文章
由于 ssh 密钥,Git 推送失败:主机密钥验证失败。从码头工人内部