首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Windows Git Clone 遠端路徑寫法:SSH URL 格式與權限

     編輯:程式設計綜合問答

本機架設 Git 伺服器 (如 Git for Windows + OpenSSH),倉庫路徑 C:\gitdemo,Clone 時 URL 應為 SSH 格式。

正確 URL 格式

git clone git@192.168.0.102:用戶名/gitdemo
  • git@:SSH 登入用戶 (通常為 git 或 Windows 帳號)。
  • 192.168.0.102:伺服器 IP。
  • 用戶名/gitdemo:相對於該用戶家目錄的倉庫路徑 (如 C:\Users\用戶名\gitdemo 或經過 Git Shell 映射的虛擬路徑)。

Windows 端 SSH 設定要點

  1. 開啟 **OpenSSH Server** 功能 (設定 → 應用程式 → 選用功能)。
  2. 設定 C:\ProgramData\ssh\sshd_config:
    Subsystem sftp sftp-server.exe
    AllowGroups sshusers (建立群組加入允許用戶)。
  3. 啟動服務:Start-Service sshd; Set-Service sshd -StartupType Automatic。
  4. 防火牆開放 22 埠:New-NetFirewallRule -Name "SSH" -DisplayName "SSH" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22。
  5. 客戶端產生金鑰:ssh-keygen -t ed25519,將 .ssh/id_ed25519.pub 內容加入伺服器 C:\Users\git\.ssh\authorized_keys。
  6. 常見錯誤

    • URL 缺少用戶名:git@192.168.0.102:gitdemo → 找不到倉庫。
    • 路徑含空格/中文需加雙引號或轉義。
    • 權限不足:確認 git 用戶對倉庫目錄有讀寫權限。

    掌握 SSH URL 格式與 Windows OpenSSH 設定,即可順利 Clone 內網 Git 倉庫。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved