Coding (現騰訊雲 CodeCC/COER) 是國內主流 Git 代碼託管平台。本文面向零基礎新手,從 Git 安裝、SSH Key 生成、公鑰配置、連接驗證、常見報錯全流程圖文級指引。
git@e.coding.net:team/project.git)git config --global user.name "你的姓名/暱稱" git config --global user.email "你的郵箱@domain.com" # 驗證 cat ~/.gitconfig # 輸出應包含 [user] name/email
# Git Bash 中執行 ssh-keygen -t ed25519 -C "你的郵箱@domain.com" # 或兼容性更好:ssh-keygen -t rsa -b 4096 -C "你的郵箱@domain.com" # 交互提示: # Enter file in which to save the key (~/.ssh/id_ed25519): # 直接回車用默認路徑 # Enter passphrase (empty for no passphrase): # 可設置密碼短語,建議設置 # Enter same passphrase again: # 確認 # 生成結果: # ~/.ssh/id_ed25519 (私鑰,絕不可外洩) # ~/.ssh/id_ed25519.pub (公鑰,需上傳到 Coding)
~/.ssh/id_ed25519.pub,複製全部內容 (以 ssh-ed25519 開頭,郵箱結尾)ssh -T git@e.coding.net # 首次連接提示: # The authenticity of host 'e.coding.net' can't be established. # ECDSA key fingerprint is SHA256:xxx. # Are you sure you want to continue connecting (yes/no)? # 輸入 yes # 成功標誌: # Hi 用戶名! You've successfully authenticated, but Coding does not provide shell access.
# 克隆項目 git clone git@e.coding.net:team/project.git cd project # 創建提交推送 echo "# README" > README.md git add . git commit -m "init" git push origin master
| 現象 | 原因 | 解決 |
|---|---|---|
Permission denied (publickey) | 公鑰未添加/私鑰路徑錯誤/SSH Agent 未載入 | 確認公鑰內容完全一致;ssh-add ~/.ssh/id_ed25519;檢查 ~/.ssh/config |
Connection timed out | 網絡不通/防火牆/端口 22 被封 | 嘗試 HTTPS 克隆;或配置 SSH over HTTPS (443 端口) |
Host key verification failed | 服務端指紋變更/中間人攻擊 | ssh-keygen -R e.coding.net 刪除 known_hosts 舊記錄 |
推送被拒絕 non-fast-forward | 遠端有他人提交,本地落後 | git pull --rebase 後再 push |
# ~/.ssh/config
Host coding-work
HostName e.coding.net
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Host coding-personal
HostName e.coding.net
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
# 使用:git clone git@coding-work:team/project.git
ssh-agent 緩存解密完成以上步驟,你已掌握 Coding SSH 協議全鏈路配置,可高效進行代碼託管、Code Review、CI/CD 集成等日常研發協作。