cd ~/.ssh
ssh-keygen -t rsa -C 你的油箱
# ‘()’裏面是默認路徑 Enter file in which to save the key (/Users/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): Enter same passphrase again:
Your identification has been saved in /Users/user/.ssh/id_rsa. Your public key has been saved in /Users/user/.ssh/id_rsa.pub. The key fingerprint is: SHA256:IQP0sSMslL9VG+HXO9oqlnFNTkeI1/m9fBiBoKIcdxk [nanananamln@163.com](mailto:nanananamln@163.com) The key’s randomart image is: +—[RSA 2048]——+ | .oo . E..o + . | | … o +o+..+ = | | ..+ O.*o…. o. | | o.=.*.o o.o o| | oo S =o..o.| | . . .oo..o.| | +. . .| | + . | | . .. | +——[SHA256]——+
# 路徑是上面的默認路徑 sudo vi /Users/malina/.ssh/id_rsa.pub
Enter file in which to save the key (/Users/user/.ssh/id_rsa):github_rsa Enter file in which to save the key (/Users/user/.ssh/id_rsa):gitlub_rsa # 由於已經在.ssh文件夾裏面,因此前面路徑不用寫
# 通常私鑰會自動添加 # 查看私鑰 ssh-add -l # 刪除私鑰 ssh-add -D # 添加私鑰 ssh-add github_rsa ssh-add gitlub_rsa # 由於已經在.ssh文件夾裏面,因此前面路徑不用寫,不然要寫成ssh-add ~/.ssh/gitlub_rsa
# ssh文件裏面沒有config直接建立便可 # 建立/更改 vim config # 內容爲: # github Host [github.com](http:#github.com/) HostName [github.com](http:#github.com/) PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa # gitlab Host [gitlab.readtv.cn](http:#gitlab.readtv.cn/) HostName [gitlab.readtv.cn](http:#gitlab.readtv.cn/) PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab_rsa
💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕💕git
若第四步設置了密碼,
那麼每次執行git pull
或者git push
,
將會提示Enter passphrase for key '/Users/user/.ssh/id_rsa':
,解決辦法以下。github
ssh-keygen -p
Enter file in which the key is(/c/Users/YourUserName/.ssh/id_rsa):