首页 > 解决方案 > GitLab 设置 ssh 密钥

问题描述

在将 git global 配置为:

$ git config --global user.name "My Username"
$ git config --global user.email "myeamil.com"

$ git clone git@gitlab.com:our-projects/this-project.git
$ cd this-project
$ touch README.md
$ git add README.md
$ git commit -m "add README"

然后按照此处描述的步骤生成并添加一个ssh key(我实际上创建了一个ED25519 SSH keys)。但是确保正确添加 ssh 的测试失败了。

$ ssh -T git@our-projects/this-project.git
ssh: Could not resolve hostname gitlab.com:it-porto/transportation-mode-detection.git: Name or service not known

$ ssh -T git@our-projects
ssh: Could not resolve hostname gitlab.com:it-porto/transportation-mode-detection.git: Name or service not known

$ ssh -T git@this-project.git
ssh: Could not resolve hostname gitlab.com:it-porto/transportation-mode-detection.git: Name or service not known

我的 ssh 密钥目录的内容:

$ ls /home/user/.ssh/
id_ed25519  id_ed25519.pub  id_rsa  id_rsa.pub  known_hosts  known_hosts.old

我该如何解决?

编辑

ssh -T git@gitlab.com按照评论中的建议做了一个,显示了一条欢迎消息,但这似乎不起作用,我无法git push使用遥控器。

$ssh -T git@gitlab.com
Welcome to GitLab, @user!

$git push origin master
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (8/8), 45.49 KiB | 3.50 MiB/s, done.
Total 8 (delta 0), reused 0 (delta 0)
remote: GitLab: 
remote: A default branch (e.g. master) does not yet exist for our-projects/this-project
remote: Ask a project Owner or Maintainer to create a default branch:
remote: 
remote:   https://gitlab.com/our-projects/this-project/-/project_members
remote: 
To gitlab.com:our-project/tthis-project.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.com:our-projects/this-project.git'


$ git remote -v
origin  git@gitlab.com:our-projects/this-projectt.git (fetch)
origin  git@gitlab.com:our-projects/this-projectt.git (push)

标签: gitsshgitlab

解决方案


你已准备好出发

Read the content of file by  cat id_rsa.pub 

并从终端复制内容,从左上角打开你的 gitlab UI,点击用户,然后设置。

转到 ssh 并将上面的内容粘贴到框中 在此处输入图像描述


推荐阅读