我的问题是我不能从GitLab中push或fetch。但是,我可以克隆(通过HTTP或SSH)。当我试图推的时候,我得到这个错误:

权限被拒绝(publickey)致命:无法从远程存储库读取

从我看过的所有线索来看,以下是我所做的:

在我的电脑上设置一个SSH密钥,并将公钥添加到GitLab 完成了用户名和电子邮件的config -global 通过SSH和HTTP克隆,以检查它是否能解决问题 执行ssh -T git@gitlab.com命令

如果您对如何解决我的问题有任何见解,我将不胜感激。


当前回答

我找了很久才找到这个。这对我来说是完美的。

Go to "Git Bash" just like cmd. Right click and "Run as Administrator". Type ssh-keygen Press enter. It will ask you to save the key to the specific directory. Press enter. It will prompt you to type password or enter without password. The public key will be created to the specific directory. Now go to the directory and open .ssh folder. You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it. Go to https://gitlab.com/-/profile/keys or Paste here in the "key" textfield. Now click on the "Title" below. It will automatically get filled. Then click "Add key".

现在试一试,肯定会管用的。

其他回答

有一个非常简单的解决方案: 与其使用SSH,不如使用https。 这样做: 在项目文件夹中有一个。git文件夹 在那里-你有一个配置文件-在文本编辑器中打开它 改变这条线

url = git@gitlab。com: yourname / yourproject git。

to

Url = https://gitlab.com/yourname/yourproject.git

在我的情况下,我使用Ubuntu有两个用户,一个是管理员用户,另一个是我,我创建了“id_rsa”和“id_rsa”。Pub”文件,而登录为我(普通用户),这些文件创建在您的”。home文件夹中的Ssh文件夹, 它可能找不到,因为它是隐藏的,所以让它可见,以检查文件是否在其中。

所以文件是在“home/”中创建的。但当我把代码推到gitlab时,我在终端上以管理员身份登录, 使用命令:su - adminName(提示输入密码)

因此“adminhome/”中没有SSH私钥。文件夹。要解决这个问题,你可以:

创建“id_rsa”和“id_rsa”。Pub”在管理配置文件(或)中 使用您的配置文件而不是管理员配置文件将代码推入gitlab。

我有gitlab运行docker,这是我所做的解决我的问题。

发现在docker /var/log/gitlab/sshd/current内部出现了多条消息:

身份验证被拒绝:文件/var/opt/gitlab/.ssh/authorized_keys的所有权或模式错误

之后,我将该文件的所有权从99:users更改为git:users:

Chown git:users authorized_keys

我在gitlab help中找到了解决方案。

To create a new SSH key pair: 
 1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
 2. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com"
 2.1 Or, if you want to use RSA: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
 3. Next, you will be prompted to input a file path to save your SSH key pair to... use the suggested path by pressing Enter
 4. Once the path is decided, you will be prompted to input a password to secure your new SSH key pair. It's a best practice to use a password, but it's not required and you can skip creating it by pressing Enter twice.
 5. Copy your public SSH key to the clipboard by using one of the commands below depending on your Operating System:
        macOS:        pbcopy < ~/.ssh/id_ed25519.pub
        WSL / GNU/Linux (requires the xclip package):      xclip -sel clip < ~/.ssh/id_ed25519.pub
        Git Bash on Windows:      cat ~/.ssh/id_ed25519.pub | clip
 6. Navigating to SSH Keys and pasting your public key in the Key field
 7. Click the Add key button

我希望它能帮助到你们中的一些人!

请使用git配置凭证。如果您的站点使用TLS/SSL, helper存储。 希望这有用