ssh密钥不能用于linux托管

时间:2017-12-12 22:45:03

标签: linux git macos ssh bitbucket

我试图在我的linux托管服务上使用带有git的ssh密钥。

我确实检查了大量的指南,但似乎没有一个对我有用,所以也许有人帮助。

这就是我所做的:

  • 我的mac上已经有一个公钥和私钥的密钥对

  • 我已将此公钥添加到bitbucket

  • 如果(从mac)我输入ssh -T git@bitbucket.org它会询问psw并且它说我登录了,这意味着它正在工作并且密钥是正确的

现在,在linux服务器主机上:

  • 我去〜/ .ssh /并且在这里我有这个文件:
  

authorized_keys - > /etc/support.pub(我无法访问它,因为   主持人限制)

     

authorized_keys2 - >与我的公共id_rsa(格式:id_rsa #######)

     

id_rsa - >我的公钥(格式:id_rsa #######)

我还创建了一个名为config的文件,如下所示:

主机bitbucket.com- {username}      HostName bitbucket.com      用户git      IdentityFile~ / .ssh / id_rsa.pub

但是当我输入:ssh -T git@bitbucket.org

我收到此错误:Permission denied (publickey).

详细日志显示:

debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 3: Applying options for *
debug1: Connecting to bitbucket.org [104.......] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version conker_1.0.315-a08d059 app-132
debug1: no match: conker_1.0.315-a08d059 app-132
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-SiteGround_Inc
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 97:8c:1b:.......
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
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: Server accepts key: pkalg ssh-rsa blen 279
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: No more authentication methods to try.
我错过了什么?这些示例,论坛或谷歌搜索都没有帮助我,也没有托管支持。

感谢您的帮助。

修改

ls -la~ / .ssh输出:

drwx------  2 user user 4096 Dec 12 17:22 .
drwx--x--x 16 user user 4096 Dec 12 16:52 ..
lrwxrwxrwx  1 user user   16 Sep 16  2014 authorized_keys -> /etc/support.pub
-rw-------  1 user user    0 Dec 12 17:23 authorized_keys2
-rw-r--r--  1 user user  381 Dec 12 17:21 id_rsa

2 个答案:

答案 0 :(得分:1)

如果authorized_keys2存在并且有效,则不会读取authorized_keys文件,因此您放入的任何内容都不会产生任何影响。 (在某些配置中可能无法读取,因为它已被弃用超过15年!)。如果您无法更改authorized_keys(例如使用网络管理界面),则无法删除密钥。

答案 1 :(得分:0)

您可以尝试以下解决方案:

1- .channel()

使用ssh-agent :(可能应包含在ssh-agent中)来管理身份:

openssh

2- > eval "$(ssh-agent -s)" > ssh-add /path/to/private_key 档案:

在客户端的~/.ssh/config设置ssh配置。以下是github配置的示例:

~/.ssh/config

3- [编辑]:通过CLI直接将路径传递给身份文件:

Host github github.com
Hostname github.com
User git
IdentityFile ~/.ssh/github 

当然,必须将公钥添加到服务器端的ssh -T git@bitbucket.org -i /path/to/key 文件中。