Quantcast
Channel: 簡睿隨筆
Viewing all articles
Browse latest Browse all 897

解決Gitea Server 的 Permission denied (publickey) 錯誤的步驟

$
0
0

不確定是否因為Windows 11更版的原因(Windows 版本 23H2 (組建 22635.4367 )),原本使用 ssh 都能順利連接的Gitea server卻收到了 Permission denied (publickey) 的被拒連線訊息,因此開始偵錯步驟。

  1. 連線測試:使用ssh命令做連線測試,無法連線成功
    ssh.exe -vT 使用者@Gitea_server.com.tw

輸出內容如下:

OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
debug1: Connecting to Gitea.Server [10.x.y.215] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\帳戶/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\帳戶/.ssh/id_rsa-cert type -1
...
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_rsa RSA SHA256:CKzolrwXAFUcSAuEFHG0eHa7D58Hka5SPVj+wC7NaPE
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_ecdsa_sk
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_ed25519_sk
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_xmss
debug1: Will attempt key: C:\\Users\\帳戶/.ssh/id_dsa
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: Email@XXXX.com.tw RSA SHA256:0gcL0QRmYka5z/7Z/E9S5/5v6PpzJSPrNLD0aECY+o8 agent
debug1: send_pubkey_test: no mutual signature algorithm
...
debug1: Trying private key: C:\\Users\\帳戶/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\帳戶/.ssh/id_ecdsa_sk
debug1: Trying private key: C:\\Users\\帳戶/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\帳戶/.ssh/id_ed25519_sk
debug1: Trying private key: C:\\Users\\帳戶/.ssh/id_xmss
debug1: Trying private key: C:\\Users\\帳戶/.ssh/id_dsa
debug1: No more authentication methods to try.
使用者@Gitea_server.com.tw: Permission denied (publickey).
  1. 重新產生新的金鑰

    ssh-keygen -t rsa -b 4096 -C "Email@XXXX.com.tw"

    連按 3 個Enter後產生金鑰:C:\Users\帳戶\.ssh\id_rsaC:\Users\帳戶\.ssh\id_rsa.pub

  2. 以id_rsa.pub的內容在Gitea server上建立新的SSH金鑰

  3. 重新測試仍然是 Permission denied (publickey) 的錯誤訊息

    解決步驟

  4. 放棄 RSA 加密演算法,改用 Ed25519 演算法

    ssh-keygen -t ed25519 -C "Email@XXXX.com.tw"
  5. 上述命令產生金鑰檔 C:\Users\帳戶\.ssh\id_ed25519C:\Users\帳戶\.ssh\id_ed25519.pub

  6. 以 id_ed25519.pub 的內容在Gitea server上建立新的SSH金鑰

再次用 ssh 測試就成功了:

~/.ssh # ssh -T 使用者@Gitea_server.com.tw
Hi there, jerry! You've successfully authenticated with the key named 金鑰名稱, but Gitea does not provide shell access.
If this is unexpected, please log in with password and setup Gitea under another user.

##

您可能也會有興趣的類似文章


Viewing all articles
Browse latest Browse all 897

Trending Articles