一. 生成ssh密钥对
- 查看本地已经有 密钥对
ls ~/.ssh/ 查看是否生成一下两个文件
./.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
待会将该文件内容添加到gitlab 的ssh key中
二.登录到gitlab,为自己的账户添加SSH key
-
点击Settings,进入用户设置
- 进入到SSH keys 设置
3.添加ssh key
cat ~/.ssh/id_rsa.pub
里面的内容粘贴进去,Title可以用自定义的也可以是默认的的。然后点击Add key
点击添加后,重新刷新一下页面就能看到