簡體   English   中英

SSH密鑰在Linux主機上不起作用

[英]ssh key not working on linux hosting

我正在Linux托管服務上嘗試將ssh密鑰與git一起使用。

我確實檢查了很多指南,但似乎沒有一個對我有用,因此也許會有一些人為幫助。

這是我所做的:

  • 我的Mac上已經有一個帶有公鑰和私鑰的密鑰對

  • 我已將此公鑰添加到bitbucket

  • 如果(從Mac上)我輸入ssh -T git@bitbucket.org,則要求輸入psw,並說我已登錄,這意味着它正在工作並且密鑰正確

現在,在linux服務器主機上:

  • 我去〜/ .ssh /,在這里我有這個文件:

authorized_keys-> /etc/support.pub(由於主機限制,我無法訪問它)

與我的公共id_rsa一起使用authorized_keys2->(格式:id_rsa #######)

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

我還創建了一個名為config的文件,如下所示:

主機bitbucket.com- {用戶名}主機名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

如果authorized_keys存在且有效,則不會讀取authorized_keys2文件,因此您在其中放置的任何內容均不會產生任何影響。 (由於某些配置已被棄用15年以上,因此在某些配置上可能還是無法閱讀!)。 如果您不能更改您的authorized_keys (例如,使用Web管理界面),那么您將無法刪除密鑰。

您可以嘗試以下解決方案:

1- ssh-agent :

使用ssh-agent (可能應該包含在openssh )來管理身份:

> eval "$(ssh-agent -s)"
> ssh-add /path/to/private_key

2- ~/.ssh/config文件:

在客戶端的~/.ssh/config上設置ssh配置。 這是github配置的示例:

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

3- [編輯]:通過CLI直接將路徑傳遞到身份文件:

ssh -T git@bitbucket.org -i /path/to/key

當然,必須將公共密鑰添加到服務器端的authorized_keys文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM