git 使用 URL 中的密码进行 SSH 登录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16267644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:28:54  来源:igfitidea点击:

SSH Login with Password in URL

gitsshjenkinspasswordsstorage

提问by Ryan

I have Jenkins cloning the Git repository at

我让詹金斯在

ssh://user@ip/repo/

ssh://user@ip/repo/

and it all works fine, but I need to login with a password, which Jenkins doesn't support. Is there a way to login with the password in the URL? Security is not an issue for me. It should end up being, and I thought it was this at first:

一切正常,但我需要使用 Jenkins 不支持的密码登录。有没有办法用URL中的密码登录?安全对我来说不是问题。它最终应该是,我一开始以为是这样的:

ssh://user:pass@ip/repo/

ssh://user:pass@ip/repo/

but it doesn't work. Thanks!

但它不起作用。谢谢!

Update #1:The git repo is on the same server.

更新 #1:git repo 在同一台服务器上。

回答by VonC

There are two reason why SSH ask you for a password:

SSH 要求您输入密码有两个原因:

  • the public key isn't found on the server, meaning ssh defaults to the account used for the ssh session, asking for its password
  • the public key is found, but the private key is password-protected.
  • 在服务器上找不到公钥,这意味着 ssh 默认为用于 ssh 会话的帐户,要求输入密码
  • 找到了公钥,但私钥受密码保护。

The first case means ssh isn't working properly: you should neverhave to enter the password of the account you are using for ssh.
The idea is to be able to authenticate someone even though all ssh connections will use one uniqueaccount. Entering the password of that unique account defeat the purpose.

第一种情况意味着 ssh 无法正常工作:您永远不必输入用于 ssh 的帐户的密码。
这个想法是能够验证某人的身份,即使所有 ssh 连接都将使用一个唯一的帐户。输入该唯一帐户的密码会破坏目的。

The second case should be easy to solve, by running ssh-agentand ssh-add.
That would allow you to notenter the password (more than once, when adding the key to the agent).

第二种情况应该很容易解决,通过运行ssh-agentssh-add
这将允许您输入密码(在向代理添加密钥时多次输入)。

回答by Steven V

Someone could correct me, I don't think this is possible since the password prompt is actually from the SSH server, and not from the SSH application. Looking at my local SSH help page, and there's no way to pass a password into SSH from the command line. This also has some serious security risk with it since the password would be available in plain text.

有人可以纠正我,我认为这是不可能的,因为密码提示实际上来自 SSH 服务器,而不是来自 SSH 应用程序。查看我的本地 SSH 帮助页面,无法从命令行将密码传递到 SSH。这也有一些严重的安全风险,因为密码将以纯文本形式提供。

With that, your best (and more secure) bet would be to do a public/private key pair which wouldn't need a password to setup. Getting this setup with Jenkins and Git can be a little challenging depending on your environment, but it is completely worth it in the end.

有了这个,你最好(也是更安全)的赌注是做一个不需要密码来设置的公钥/私钥对。根据您的环境,使用 Jenkins 和 Git 进行此设置可能有点挑战性,但最终是完全值得的。