git - 无法通过SSH访问远程存储库(权限被拒绝(公钥))

标签 git ssh gitlab

我更换了笔记本电脑,现在w当我尝试执行git clone git@...(使用SSH)时,出现以下错误消息:

Cloning into 'test'... Permission denied (publickey). fatal: Could not read from remote repository.

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



我做了以下步骤。由于能够从旧笔记本电脑克隆存储库,因此我决定将~/.ssh的内容从旧笔记本电脑复制粘贴到新笔记本电脑。我只删除了known_hosts文件。在文件夹~/.ssh中,我有文件config:
Host server2 
Hostname xxxxxx 
User xxxxx
IdentityFile "~/.ssh/id_rsa"

我也有id_rsaid_rsa.pub。这与我的旧笔记本电脑上的内容相同。

因此,我不了解问题的根源。我的设置是否有问题,还是应该联系存储库的管理员?

更新:

这是我输入ssh -vT git@gitlab.test.org时得到的:
OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g-fips  1 Mar 2016
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gitlab.test.org [42.12.212.10] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to gitlab.test.org:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
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:ttfy7K7NFEj913pHVx3lG4
debug1: Host 'gitlab.test.org' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Trying private key: /home/user/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

最佳答案

我通过运行chmod 400 ~/.ssh/id_rsa解决了这个问题。

关于git - 无法通过SSH访问远程存储库(权限被拒绝(公钥)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38566475/

相关文章:

linux - Shell 脚本不会在 jenkins 上执行,但是它会手动执行

git - 删除git中的分支会导致gitk疯狂

debian - Gitlab-ci, image debian :jessie. 无法使用 su 命令更改用户

git 撤消对过去提交的 checkout

bash - 在远程计算机上运行bash脚本的一部分

git - 使用 ssh 连接到实时服务器并将我的 git 推送到其中

windows - 系统准备服务器后 Git 远程不工作

docker - 语法错误的 Gitlab-runner

gitlab - 如何从命令行获取 GitLab 个人访问 token

来自 IntelliJ IDEA 的 Git push --force