用SSH協(xié)議代替HTTPS協(xié)議)
用git clone指令獲取資源時(shí)對(duì)網(wǎng)絡(luò)要求較高這時(shí)候可以將HTTPS協(xié)議換成SSH協(xié)議SSH比HTTPS在Git操作中通常更快且更穩(wěn)定尤其在大型倉(cāng)庫(kù)和頻繁操作時(shí)差異顯著。使用SSH需要將SSH Key添加到GitHub賬戶第一步檢查是否有SSH Keyls -la ~/.ssh如果看到 id_rsa.pub 或 id_ed25519.pub 說(shuō)明已有密鑰可跳到第三步。第二步生成新的SSH Keyssh-keygen -t ed25519 -C 你的GitHub郵箱example.com- 提示 Enter file in which to save the key 直接回車用默認(rèn)路徑- 提示 Enter passphrase 可直接回車免密也可設(shè)置密碼第三步啟動(dòng) ssh-agent 并添加密鑰eval $(ssh-agent -s) ssh-add ~/.ssh/id_ed25519第四步復(fù)制公鑰內(nèi)容cat ~/.ssh/id_ed25519.pub復(fù)制輸出的全部?jī)?nèi)容以 ssh-ed25519 開頭的一整行第五步將公鑰添加到 GitHub1. 登錄 GitHub2. 右上角頭像 → Settings3. 左側(cè) SSH and GPG keys4. 點(diǎn)擊 New SSH key5. Title 隨便填Key 粘貼公鑰內(nèi)容6. 點(diǎn)擊 Add SSH key第六步測(cè)試連接ssh -T gitgithub.com看到 Hi xxx! Youve successfully authenticated 說(shuō)明成功第七步用 SSH 克隆git clone gitgithub.com:用戶名/倉(cāng)庫(kù)名.gitHTTPS協(xié)議和SSH協(xié)議兩種方法的命令格式對(duì)比如下HTTPS協(xié)議git clone https://github.com/friendlyarm/kernel-rockchip.git kernel-rockchipSSH協(xié)議git clone gitgithub.com:friendlyarm/kernel-rockchip.git kernel-rockchip用ssh傳輸文件時(shí)由于網(wǎng)絡(luò)不好會(huì)異常斷可以添加?;顓?shù)命令如下:scp -o ServerAliveInterval30 -o ServerAliveCountMax20 -C -l 20480 D:\rk3399_backup\rk3399_full_backup.tar.gz root192.168.0.136:/tmp/