不確定是否因為Windows 11更版的原因(Windows 版本 23H2 (組建 22635.4367 )),原本使用 ssh 都能順利連接的Gitea server卻收到了 Permission denied (publickey) 的被拒連線訊息,因此開始偵錯步驟。
- 連線測試:使用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).
-
重新產生新的金鑰
ssh-keygen -t rsa -b 4096 -C "Email@XXXX.com.tw"
連按 3 個Enter後產生金鑰:
C:\Users\帳戶\.ssh\id_rsa
與C:\Users\帳戶\.ssh\id_rsa.pub
-
以id_rsa.pub的內容在Gitea server上建立新的SSH金鑰
-
重新測試仍然是 Permission denied (publickey) 的錯誤訊息
解決步驟
-
放棄 RSA 加密演算法,改用 Ed25519 演算法
ssh-keygen -t ed25519 -C "Email@XXXX.com.tw"
-
上述命令產生金鑰檔
C:\Users\帳戶\.ssh\id_ed25519
與C:\Users\帳戶\.ssh\id_ed25519.pub
-
以 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.
##
您可能也會有興趣的類似文章
- 啟用Gitea Server的SSH服務,可大幅增加連線速度 (0則留言, 2018/02/15)
- Gitea網頁添加自訂選項以開啟說明文件 (0則留言, 2022/09/01)
- 幫Gitea網站使用Let’s Encrypt SSL憑證的設定步驟 (0則留言, 2022/09/01)
- [Git#9] Gitea 安裝與設定:輕量級程式碼託管解決方案 (0則留言, 2022/05/22)
- Git https/SSL 連線失敗時的解決方法 (0則留言, 2022/09/06)
- [Git #2] 產生SSH金鑰,讓SmartGit與GitHub連線 (0則留言, 2019/12/29)
- 定時刪除Gitea的SQLite3資料 (0則留言, 2024/01/01)
- [分享] 濱野純訪談:為什麼 Google 接管開發 Git 2.0 了? (0則留言, 2018/05/25)
- 將Git分支名稱加到提示字元(Prompt)裡 (0則留言, 2014/09/02)
- [Windows] 用Gitea架設自用的Git Server (2則留言, 2017/07/21)
- 建立測試環境以git rebase -i變更Commit歷史 (0則留言, 2014/10/08)
- Subversion版本庫匯入Git的步驟與SVN整合步驟 (0則留言, 2014/10/03)
- Git的Staging Area的中文翻譯探討 (2則留言, 2014/09/12)
- [Batch#3 Git#3] 如何在Windows批次檔裡將提示字元變更為Git分支名稱? (初學者的命令行 #7) (0則留言, 2020/01/05)
- 撰寫git info工具以模擬svn info功能 (0則留言, 2014/09/01)