一. 生成ssh密鑰對
- 查看本地已經(jīng)有 密鑰對
ls ~/.ssh/ 查看是否生成一下兩個(gè)文件
./.ssh/
├── id_rsa
└── id_rsa.pub
- 生成密鑰對
ssh-kengen
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:xBhmVIxxxxxxxxxxxxxxxxxxxxxxxx root@gitlab.example.com
The key's randomart image is:
+---[RSA 2048]----+
| ..E*. |
| ..+o.+ |
| o.+. o |
| . o . B . o |
| + +. S = . . |
| *+++ = + |
| *.o* . o |
| .+*.o |
| .==*. |
+----[SHA256]-----+
cat ~/.ssh/id_rsa.pub 待會(huì)將該文件內(nèi)容添加到gitlab 的ssh key中
二.登錄到gitlab,為自己的賬戶添加SSH key
-
點(diǎn)擊Settings,進(jìn)入用戶設(shè)置
image.png - 進(jìn)入到SSH keys 設(shè)置
image.png
3.添加ssh key
cat ~/.ssh/id_rsa.pub里面的內(nèi)容粘貼進(jìn)去,Title可以用自定義的也可以是默認(rèn)的的。然后點(diǎn)擊Add key

image.png
點(diǎn)擊添加后,重新刷新一下頁面就能看到

image.png

