【问题标题】:SSH GitLab pull always asks for passwordSSH GitLab pull 总是要求输入密码
【发布时间】:2021-11-23 08:28:57
【问题描述】:

(特别是 GitLab!(GitHub 没有问题))
我正在尝试创建一个脚本以从 main GitLab 分支中提取项目而不要求输入密码。几台远程计算机有一个信息亭模式项目。总是手动连接到它们有点无聊 - 而不是让 cron-job 自动拉出自动

我已设置为使用 SSH,并创建并添加了我的 SSH ed25519 密钥。
./.git/config 中添加了正确的url,例如:

[remote "origin"]
    url = git@gitlab.com:<ME>/<REPO>.git

&lt;ME&gt;&lt;REPO&gt; 是我的用户名和存储库:)

使用git pullfetch总是要求输入密码。在我的 GitHub 存储库中不会发生同样的情况。

我设法使它工作的唯一方法是使用 Personal Access Token 之类的:

[remote "origin"]
    url = https://oauth2:<MY P. A. TOKEN>@gitlab.com/<ME>/<REPO>.git

但我不喜欢令牌以明文形式出现并且必须做超出 SSH 握手范围的事情。

我是否缺少特定于 GitLab 的东西?我能够搜索的每个帮助页面都只是谈论设置我已经做过的正确的 SSH URI(git@gitlab.com ..... 等)。但每次我触发git pull 时,它不断要求输入密码

窗户。 Git Bash。

感谢任何帮助、技巧或见解。

【问题讨论】:

  • 您的 ssh 密钥是否有密码保护它?
  • @AdamMarshall 是的。我这边犯了一个愚蠢的错误。

标签: git ssh gitlab


【解决方案1】:

您的 ssh 密钥是使用密码生成的,这就是它要求您输入密码的原因。


无密码SSH登录

你的目标

您想使用 Linux 和 OpenSSH 来自动化您的任务。因此,您需要从主机 A / 用户 a 自动登录到主机 B / 用户 b。您不想输入任何密码,因为您想从 shell 脚本中调用 ssh。

怎么做 首先以用户 a 的身份登录 A 并生成一对认证密钥。不要输入密码:

a@A:~> ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase: (THIS IS THE CATCH, just press enter here to leave it empty): 
Enter same passphrase again: (press enter again)
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

a@A:~> ssh-copy-id remote_username@remote_domain

or

a@A:~> ssh-copy-id remote_username@remote_IP

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remote_username@remote_domain password: 

它会要求您输入远程服务器上远程用户的密码

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '22' 'remote_username@remote_domain'"
and check to make sure that only the key(s) you wanted were added.

现在尝试登录

a@A:~> ssh remote_username@remote_domain

你应该进去


来源:http://www.linuxproblem.org/art_9.html

【讨论】:

  • Gitlab 文档特别指示您使用密码:docs.gitlab.com/ee/ssh/#generate-an-ssh-key-pair
  • 是的,因为它更安全。但是制作没有密码的 ssh 密钥的唯一目的是让您不必插入密码,您只需 ssh 自动进入服务器。可能超过 95% 的开发人员不设置密码是因为我们很懒惰,而且密钥被盗或被黑客入侵的机会与有人窃取您的笔记本电脑/电脑一样
  • 对,但是正确的方法是通过设置~/.ssh/config。这样您就可以避免您的密钥被盗/被黑并且无需在每次拉取或推送时输入密码
  • ssh-copy-id my_gitlab_username@gitlab.com ... 结果:“my_gitlab_username@gitlab.com: Permission denied (publickey,keyboard-interactive)”... NB OS 是 Linux Mint 20。您建议的另一个解决方案是“ remote_username@remote_IP"...我如何找到远程IP(即Gitlab)?
  • gitlab.com 是 gitlab 的官方网站...您不应该连接到该网站...所有这些示例都是针对自托管 gitlab...当您公开自己的服务器(购买域名和主机存储提供商)我希望这会有所帮助。
猜你喜欢
  • 2019-10-04
  • 2018-09-22
  • 2019-03-07
  • 1970-01-01
  • 2013-09-30
  • 2012-04-02
  • 2013-03-17
  • 2014-05-30
  • 2021-03-29
相关资源
最近更新 更多