为GitLab帐号添加SSH keys并连接GitLab

Docker-compose File

vim gitlab-docker-compose.yml


[为隐藏内容,请登录(login)以显示!]

Generating a new SSH key

ssh-keygen -t rsa -b 4096 -C "ec-310S" -f ~/.ssh/id_rsa


[为隐藏内容,请登录(login)以显示!]

ec@ec-310S:~/.ssh$ ssh-keygen -t rsa -b 4096 -C "ec-310S" -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ec/.ssh/id_rsa.
Your public key has been saved in /home/ec/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:CztoW0ywOPfLsjX0j8aQ7HAAKIwn3AdU2C0H.... ec-310S
The key's randomart image is:
+---[RSA 4096]----+
|+.+*Boo          |
|=o++ + o         |
|.o..o o          |
| . ..o           |
|  = oo+.S        |
| o =.*=+ .       |
|  + o+Ooo        |
| E ..=.+oo       |
|    ooo.. .      |
+----[SHA256]-----+

Adding an SSH key to your GitLab account

添加生成的 ssh key 到 gitlab 用户

vim ~/.ssh/id_rsa.pub
Settings -> SSH Key -> Add key

Testing that everything is set up correctly

To test whether your SSH key was added correctly, run the following command in your terminal (replacing d0o0bz.cn, 3222 with your GitLab’s instance domain and ssh port):

ssh -p 3222 git@d0o0bz.cn
ec@ec-310S:~/gitbab$ ssh -p 3222 git@d0o0bz.cn
The authenticity of host '[d0o0bz.cn]:3222 ([111.230.249.109]:3222)' can't be established.
ECDSA key fingerprint is SHA256:RIt5gBx4iRemGxrsPTaHmUfTqXeXoXT+Z+eEDN1/Pis.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[d0o0bz.cn]:3222,[111.230.249.109]:3222' (ECDSA) to the list of known hosts.
PTY allocation request failed on channel 0
Welcome to GitLab, @root!
Connection to d0o0bz.cn closed.

Git global setup

git config --global user.name "e.c.310s"
git config --global user.email "e.c.admin@d0o0bz.cn"

Create a new repository

git clone ssh://git@d0o0bz.cn:3222/root/html-css.git
cd html-css
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
ec@ec-310S:~/gitbab$ git config --global user.name "e.c.310s"
ec@ec-310S:~/gitbab$ git config --global user.email "e.c.admin@d0o0bz.cn"

ec@ec-310S:~/gitbab$ git clone ssh://git@d0o0bz.cn:3222/root/html-css.git
Cloning into 'html-css'...
warning: You appear to have cloned an empty repository.

ec@ec-310S:~/gitbab$ cd html-css/

ec@ec-310S:~/gitbab/html-css$ ls -a
.  ..  .git
ec@ec-310S:~/gitbab/html-css$ touch README.md
ec@ec-310S:~/gitbab/html-css$ git add README.md

ec@ec-310S:~/gitbab/html-css$ git commit -m "add README"
[master (root-commit) 967b2ad] add README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md

ec@ec-310S:~/gitbab/html-css$ git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 214 bytes | 107.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://d0o0bz.cn:3222/root/html-css.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.