如何git push/clone 免打密碼 ?
使用時機:
不想每次git push時都要打密碼
環境:
A (192.168.0.101) Ubuntu (開發機)B (192.168.0.100) Synology DS + Synology Git Server
概念:
在A上把public key generate出來後放到B上,並且設定好ssh即可做到ssh免密碼登入。因為git push/clone都是走ssh,所以就可以在push/clone時免打密碼。
SSH Key Generate: (on A)
ssh-keygen -t rsa (產生/root/.ssh/id_rsa 以及/root/.ssh/id_rsa.pub)
NOTE:注意當問"Enter passphrase (empty for no passphrase):"直接enter即可,否則還是會需要輸入一個passpharse
Copy public key to B: (on A)
scp /root/.ssh/id_rsa.pub 192.168.0.100:/root/.ssh/id_rsa.git.pub
Set default git user name: (on A)
vim /root/.gitconfig
----------------------------------------------
[user]
name = root
^^^^^ 必須和 B 上的git init --bare的目錄是同個owner
Concat content into authorized_keys: (on B)
cat /root/.ssh/id_rsa.git.pub >> /root/.ssh/authorized_keys
成功後就可以從A ssh到B、A git clone/push B的project而不用輸入密碼
沒有留言:
張貼留言