產生 ssh key 和將 ssh key 加入 gitlab 或其他平台
新增產生 shh key 及平台增加公鑰 ssh key generated & add to gitlab or other
設定本機私鑰 Configure ssh key
ssh key generated & add to gitlab or other
產生 ssh key 和將 ssh key 加入 gitlab 或其他平台
可協助其他人產生 ssh key
區分為 public 和 private key
public 新增上版控平台,private key 給予使用者
Generate a new SSH Key
產生新的 ssh key 使用 ed25519
預使用其他算法,可至平台查詢
See if you have an existing SSH key pair
- Open Git Bash or Terminal.
- Run the following command:
- Press Enter. Output similar to the following is displayed:
- Next all press Enter to accept the default location and file name.
Add an SSH key to your GitLab account
將 public key 新增至平台,以下 gitlab 舉例
To use SSH with GitLab, copy your public key to your GitLab account:
- Copy the contents of your public key file. You can do this manually or use a script. For example, to copy an ED25519 key to the clipboard:\
複製 public key
a. mac
b. Linux (requies the xclip package)
c. Git Bash on Windows
- Sign in to GitLab.
登入你的 gitlab
- On the left sidebar, select your avatar.
尋找側邊欄,或任一位置的頭像
- Select Edit profile.
點擊頭像後,尋找編輯設定
- On the left sidebar, select SSH Keys.
進入設定,側邊欄會出現 SSH Keys
- Select Add public key.
選擇後新增 public key
unix 有權限問題,參考以下指令
- Run the following command:
unix 需要使用該指令,將 ssh-agent 設定至環境變數。
- ssh-add adds private key identities to the authentication agent.
- Save these settings in the ~/.ssh/config file. For example:
Now, to clone a repository for user_1
, use user_1.gitlab.com
in the git clone
command:
To update a previously-cloned repository that is aliased as origin
:
Use different accounts on a single GitLab instance
go get different key
Windows
SET GIT_SSH_COMMAND=ssh -i C:\path\to\your\key
Account Identity
Verify that you can connect to GitLab
驗證你的帳戶是否可連接
成功後,你應該會接收到該訊息 Welcome to GitLab, @username!
後面為你的 username
失敗後,可以使用以下指令看到更資訊除錯
Use SSH on Microsoft Windows
- Git for Windows: C:\Users<user>
參考
https://docs.gitlab.com/ee/user/ssh.html