如何配置 Mercurial 进行推送而不通过 ssh 询问我的密码?

发布于 2024-09-16 03:10:38 字数 122 浏览 11 评论 0原文

我在项目中使用 Mercurial,每次通过 ssh 将新的变更集推送到服务器时,它都会要求我输入密码。
那么如何配置mercurial在不询问密码的情况下进行推送呢?

我在 Ubuntu 9.10 上工作

I use mercurial in my project, and every time I push new changesets to the server by ssh, it ask me for a password.
Then how to config the mercurial to push with out asking password?

I works on Ubuntu 9.10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鸵鸟症 2024-09-23 03:10:38

在 Linux 和 Mac 上,使用 ssh-agent

  1. 确保您有 ssh 密钥对(有关详细信息,请参阅 man ssh-keygen
  2. 将您的公钥(从 ~/.ssh/id_dsa.pub)复制到远程计算机,给出它是一个唯一的名称(例如myhost_key.pub
  3. 正常登录远程计算机并将刚刚复制的公钥附加到~/.ssh/authorized_keys文件中
  4. 运行在本地工作站上使用 ssh-add 将密钥添加到钥匙串中

您现在可以在此会话中使用任何远程 hg 命令,而无需进行身份验证。

On Linux and Mac, use ssh-agent.

  1. Ensure you have an ssh keypair (see man ssh-keygen for details)
  2. Copy your public key (from ~/.ssh/id_dsa.pub) to the remote machine, giving it a unique name (such as myhost_key.pub)
  3. Log in to the remote machine normally and append the public key you just copied to the ~/.ssh/authorized_keys file
  4. Run ssh-add on your local workstation to add your key to the keychain

You can now use any remote hg commands in this session without requiring authentication.

寄离 2024-09-23 03:10:38

假设您使用的是 Windows,请阅读我的 Mercurial/SSH 指南。在帖子底部,您将找到有关如何使用 PuTTy 为您做这件事。

编辑:--这是我正在谈论的帖子的一部分(请记住,您需要在已加载密钥的情况下运行选美才能使其工作):


客户端:设置 Mercurial

如果您尚未安装 Mercurial,请确保使用默认设置在客户端计算机上安装 Mercurial。确保告诉安装程序将 Mercurial 路径添加到系统路径中。

客户端配置的最后一步是告诉 Mercurial 在使用 SSH 时使用 PuTTy 工具。 Mercurial 可以通过名为 .hgrc 的用户特定配置文件进行配置。在 Windows 上,它也可以称为 Mercurial.ini。该文件位于您的主文件夹中。如果您不知道主文件夹是什么,只需打开命令提示符并输入 echo %USERPROFILE% - 这将告诉您路径。

如果您尚未设置配置,则配置文件很可能不存在。所以你必须创建它。手动在主文件夹中创建一个名为 .hgrc 或 Mercurial.ini 的文件,然后在文本编辑器中打开它。这是我的部分的样子:

[ui]
username = OJ Reeves

editor = vim
ssh = plink -ssh -i "C:/path/to/key/id_rsa.ppk" -C -agent

最后一行是关键,这是您确保其正确设置所需要的。我们告诉 Mercurial 使用 plink 程序。它也随 PuTTy 一起提供,是 PuTTY 程序本身在幕后执行的操作的命令行版本。我们还添加了一些参数:

  • -ssh :表示我们正在使用 SSH 协议。
  • -i "file.ppk" :指定我们要用来登录远程服务器的私钥文件的位置。将此更改为指向您本地的与 putty 兼容的 ppk 私钥。确保您也使用正斜杠作为路径分隔符!
  • -C:此开关启用压缩。
  • -agent :这告诉 plink 与选美实用程序对话以获取密钥的密码,而不是以交互方式询问您。

客户现在已经准备好摇滚了!

Assuming you're using Windows, have a read of my Mercurial/SSH guide. Down the bottom of the post you'll find info on how to use PuTTy to do this for you.

Edit: -- Here's the part of the post that I'm talking about (bear in mind you'll need to have pageant running with your key already loaded for this to work):


Client: Setting up Mercurial

If you haven't already, make sure you install Mercurial on the client machine using the default settings. Make sure you tell the installer to add the Mercurial path to the system PATH.

The last step of configuration for the client is to tell Mercurial to use the PuTTy tools when using SSH. Mercurial can be configured by a user-specific configuration file called .hgrc. On Windows it can also be called Mercurial.ini. The file is located in your home folder. If you don't know what your home folder is, simply open a command prompt and type echo %USERPROFILE% - this will tell you the path.

If you haven't set up your configuration yet, then chances are the configuration file doesn't exist. So you'll have to create it. Create a file call either .hgrc or Mercurial.ini in your home folder manually, and open it in a text editor. Here is what part of mine looks like:

[ui]
username = OJ Reeves

editor = vim
ssh = plink -ssh -i "C:/path/to/key/id_rsa.ppk" -C -agent

The last line is the key and this is what you need to make sure it set properly. We are telling Mercurial to use the plink program. This also comes with PuTTy and is a command-line version of what the PuTTY program itself does behind the scenes. We also add a few parameters:

  • -ssh : Indicates that we're using the SSH protocol.
  • -i "file.ppk" : Specifies the location of the private key file we want to use to log in to the remote server. Change this to point to your local putty-compatible ppk private key. Make sure you user forward-slashes for the path separators as well!
  • -C : This switch enables compression.
  • -agent : This tells plink to talk to the pageant utility to get the passphrase for the key instead of asking you for it interactively.

The client is now ready to rock!

素罗衫 2024-09-23 03:10:38

安装 PuTTY

如果您使用的是 Windows,请在您喜欢的文本编辑器中打开 projectdir/.hg/hgrc。将其编辑为如下所示:

[paths]
default = ssh://[email protected]/name/project

[ui]
username = Your Name <[email protected]>
ssh = "C:\Program Files (x86)\PuTTY\plink.exe" -ssh -i "C:\path\to\your\private_key.ppk" -C -agent

如果需要永远推送,服务器可能会尝试问您一个问题(但不会显示)。

运行此命令:

"C:\Program Files (x86)\PuTTY\plink.exe" -T [email protected] -i "C:\Program Files (x86)\PuTTY\plink.exe" -ssh -i "C:\path\to\your\private_key.ppk"

回答任何问题,然后再次尝试推送。

如果您使用的是 Bitbucket,请使用 puttygen 打开您的私钥,从顶部文本框中复制您的公钥,然后将其添加到您的用户帐户: https://bitbucket.org/account/user/USERNAME/ssh-keys/

Install PuTTY.

If you're on Windows, open projectdir/.hg/hgrc in your favorite text editor. Edit it to look like this:

[paths]
default = ssh://[email protected]/name/project

[ui]
username = Your Name <[email protected]>
ssh = "C:\Program Files (x86)\PuTTY\plink.exe" -ssh -i "C:\path\to\your\private_key.ppk" -C -agent

If it's taking forever to push, the server might be trying to ask you a question (but it's not displayed).

Run this:

"C:\Program Files (x86)\PuTTY\plink.exe" -T [email protected] -i "C:\Program Files (x86)\PuTTY\plink.exe" -ssh -i "C:\path\to\your\private_key.ppk"

Answer any questions, and then try pushing again.

If you're using Bitbucket, open your private key with puttygen, copy your public key out of the top textbox, and add it to your user account: https://bitbucket.org/account/user/USERNAME/ssh-keys/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文