我在一个个人项目中使用Mercurial,每次我想向服务器推送一些东西时,我都要输入我的用户名和密码。

我尝试将以下内容添加到主目录中的.hgrc文件中,但它似乎完全被忽略了。

[ui]
username = MY_USER_NAME
password = MY_PASSWORD

如何正确地做到这一点?


当前回答

虽然它在您的情况下可能工作,也可能不工作,但我发现使用Putty的Pageant生成公钥/私钥非常有用。

如果你也在使用bitbucket (.org),它应该能让你为你的用户帐户提供一个公钥,然后到达存储库的命令将被自动保护。

如果重新启动后Pageant没有启动,您可以在Windows“开始菜单”中添加Pageant的快捷方式,并且该快捷方式可能需要有一个“属性”,其中包含您的私人(.ppk)文件的位置。

有了这些,需要将Mercurial和本地存储库设置为使用SSH格式进行推送/拉取。

以下是Atlassian网站上针对Windows或Mac/Linux的一些详细说明。

你不必相信我的话,毫无疑问还有其他方法可以做到这一点。也许这里描述的这些步骤更适合你:

Start PuttyGen from Start -> PuTTY-> PuttyGen Generate a new key and save it as a .ppk file without a passphrase Use Putty to login to the server you want to connect to Append the Public Key text from PuttyGen to the text of ~/.ssh/authorized_keys Create a shortcut to your .ppk file from Start -> Putty to Start -> Startup Select the .ppk shortcut from the Startup menu (this will happen automatically at every startup) See the Pageant icon in the system tray? Right-click it and select “New session” Enter username@hostname in the “Host name” field You will now log in automatically.

其他回答

在Mac OSX上使用MacPorts安装mercural_keyring:

sudo port install py-keyring
sudo port install py-mercurial_keyring

在~/.hgrc中添加以下内容:

# Add your username if you haven't already done so.
[ui]
username = email@address.com

[extensions]
mercurial_keyring =

如果您正在使用TortoiseHg,您必须执行附件屏幕截图中显示的这三个步骤,这将为您正在使用的特定存储库添加您的凭据。

要添加全局设置,您可以访问文件C:\users\user.name\ mercury .ini并添加section

[auth]
bb.prefix=https://bitbucket.org/zambezia/packagemanager
bb.username = $username
bb.password = $password

希望这能有所帮助。

你可以在你的.hgrc或mercury .ini文件中创建一个认证部分,如下所示:

[auth]
bb.prefix = https://bitbucket.org/repo/path
bb.username = foo
bb.password = foo_passwd

' bb '部分是一个任意标识符,用于将前缀与用户名和密码匹配-方便管理不同站点的不同用户名/密码组合(前缀)

您也可以只指定用户名,然后在按下按钮时只需输入密码。

我还建议看看密匙环扩展。因为它将密码存储在系统的密匙环中,而不是纯文本文件,所以更安全。它在Windows上与TortoiseHg捆绑在一起,目前正在讨论将其作为捆绑扩展分发到所有平台上。

一个简单的破解方法是在项目的。hg/hgrc文件中添加用户名和密码到推送url:

[paths]
default = http://username:password@mydomain.com/myproject

(注意,通过这种方式,您可以以纯文本的形式存储密码)

如果您在同一个域下处理多个项目,您可能希望在~/中添加一个重写规则。HGRC文件,以避免对所有项目重复此操作:

[rewrite]
http.//mydomain.com = http://username:password@mydomain.com

同样,由于密码是以纯文本形式存储的,所以我通常只存储我的用户名。

如果你在Gnome下工作,我在这里解释如何集成Mercurial和Gnome Keyring:

http://aloiroberto.wordpress.com/2009/09/16/mercurial-gnome-keyring-integration/

没人提到密匙环扩展。它会将用户名和密码保存到系统密匙环中,这比上面提到的将密码存储在静态文件中要安全得多。执行下面的步骤,您就可以开始了。我用了大约2分钟就在Ubuntu上安装并运行了它。

>> sudo apt-get install python-pip
>> sudo pip install keyring
>> sudo pip install mercurial_keyring

**Edit your .hgrc file to include the extension**
[extensions]
mercurial_keyring = 

https://www.mercurial-scm.org/wiki/KeyringExtension