mac系統下:git
經過以下步驟可成功切換到新帳號:shell
git config --global user.name 查看當前用戶名
git config --global user.email 查看當前郵箱
git config --global user.name "Your Name" 切換用戶爲您的用戶名
git config --global user.email you@example.com 切換郵箱爲您的git郵箱
複製代碼
cd ~/.ssh
複製代碼
$ ssh-keygen -t rsa -C 「你的郵箱」//注意C必定要大寫
複製代碼
按3個回車,不設密碼bash
文件存放位置 ~/.sshdom
若是是window的話就在:C:\Users\Administrator.ssh 下面ssh
若是是mac,在執行指令的目錄(如mac打包機爲:/User/zxl01/.ssh下)ide
Your identification has been saved in id_rsa. // 私鑰
Your public key has been saved in id_rsa.pub. // 公鑰
The key fingerprint is:
SHA256:IL6L2NjBQDAAuYfD6NzTbR8VIc/fJl1coDUhzL3LYP8 leyu@chargedot.com
The key's randomart image is:
+---[RSA 2048]----+
|B. . +o.=o.|
|o. +.o+.o.|
|o+ . . oo .o|
|*... . . .+ + .|
|+o. o . S .. * = |
| = o o o . * |
| o o . . . . |
| = o . . E|
|o + . |
+----[SHA256]-----+
複製代碼
打開公鑰,複製公鑰粘貼到 gitlab上設置 ssh Key 的地方gitlab
cat id_rsa.pub
複製代碼
打開gitlab-->點擊Profile Settings,而後: spa
LELEdeMacBook-Pro:.ssh lele$ ssh-add id_rsa // 添加私鑰
Enter passphrase for id_rsa: // 若是前面沒有設密碼,就不會有這個
Identity added: id_rsa (id_rsa) //出現這個,說明你成功設置了
複製代碼
注意:一段時間後,若是出現提交或拉取代碼失敗,需從新在終端添加私鑰便可.net