我在一个个人项目中使用Mercurial,每次我想向服务器推送一些东西时,我都要输入我的用户名和密码。
我尝试将以下内容添加到主目录中的.hgrc文件中,但它似乎完全被忽略了。
[ui]
username = MY_USER_NAME
password = MY_PASSWORD
如何正确地做到这一点?
我在一个个人项目中使用Mercurial,每次我想向服务器推送一些东西时,我都要输入我的用户名和密码。
我尝试将以下内容添加到主目录中的.hgrc文件中,但它似乎完全被忽略了。
[ui]
username = MY_USER_NAME
password = MY_PASSWORD
如何正确地做到这一点?
当前回答
有三种方法:使用.hgrc文件,使用ssh或使用keyring扩展名
1. 不安全的方式-更新您的~/。hgrc文件
适合我的格式(在我的~/。HGRC文件)是这样的
[ui]
username=Chris McCauley <chris.mccauley@mydomain.com>
[auth]
repo.prefix = https://server/repo_path
repo.username = username
repo.password = password
You can configure as many repos as you want by adding more triplets of prefix,username, password by prepending a unique tag. This only works in Mercurial 1.3 and obviously your username and password are in plain text - not good. 2. The secure way - Use SSH to AVOID using passwords Mercurial fully supports SSH so we can take advantage of SSH's ability to log into a server without a password - you do a once off configuration to provide a self-generated certificate. This is by far the safest way to do what you want. You can find more information on configuring passwordless login here 3. The keyring Extension If you want a secure option, but aren't familiar with SSH, why not try this? From the docs ... The extension prompts for the HTTP password on the first pull/push to/from given remote repository (just like it is done by default), but saves the password (keyed by the combination of username and remote repository url) in the password database. On the next run it checks for the username in .hg/hgrc, then for suitable password in the password database, and uses those credentials if found. There is more detailed information here
其他回答
有三种方法:使用.hgrc文件,使用ssh或使用keyring扩展名
1. 不安全的方式-更新您的~/。hgrc文件
适合我的格式(在我的~/。HGRC文件)是这样的
[ui]
username=Chris McCauley <chris.mccauley@mydomain.com>
[auth]
repo.prefix = https://server/repo_path
repo.username = username
repo.password = password
You can configure as many repos as you want by adding more triplets of prefix,username, password by prepending a unique tag. This only works in Mercurial 1.3 and obviously your username and password are in plain text - not good. 2. The secure way - Use SSH to AVOID using passwords Mercurial fully supports SSH so we can take advantage of SSH's ability to log into a server without a password - you do a once off configuration to provide a self-generated certificate. This is by far the safest way to do what you want. You can find more information on configuring passwordless login here 3. The keyring Extension If you want a secure option, but aren't familiar with SSH, why not try this? From the docs ... The extension prompts for the HTTP password on the first pull/push to/from given remote repository (just like it is done by default), but saves the password (keyed by the combination of username and remote repository url) in the password database. On the next run it checks for the username in .hg/hgrc, then for suitable password in the password database, and uses those credentials if found. There is more detailed information here
在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 =
虽然它在您的情况下可能工作,也可能不工作,但我发现使用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.
如果您正在使用TortoiseHg,您必须执行附件屏幕截图中显示的这三个步骤,这将为您正在使用的特定存储库添加您的凭据。
要添加全局设置,您可以访问文件C:\users\user.name\ mercury .ini并添加section
[auth]
bb.prefix=https://bitbucket.org/zambezia/packagemanager
bb.username = $username
bb.password = $password
希望这能有所帮助。
上面没有人向新手解释/澄清术语。他们被这些术语弄糊涂了
.hg/hgrc——此文件用于存储库,在本地/工作空间位置/实际存储库的.hg文件夹中。
~ /。HGRC——这个文件与下面的文件不同。该文件位于~或主目录。
myremote.xxxx =… bb.xxxx =……
This is one of the lines under [auth] section/directive, while using mercurial keyring extension. Make sure the server name you put there, matches with what you use while doing "hg clone" otherwise keyring will say, user not found. bb or myremote in the line below, are "alias name" that you MUST give while doing "hg clone http:/.../../repo1 bb or myremote" otherwise, it wont work or you have to make sure your local repository's .hg/hgrc file contain same alias, ie (what you gave while doing hg clone .. as last parameter).
PS以下链接为清晰的细节,抱歉太快写语法。
https://stackoverflow.com/questions/14267873/mercurial-hg-no-changes-found-cant-hg-push-out/14269997#14269997 http://www.linuxquestions.org/questions/showthread.php?p=4867412#post4867412 https://stackoverflow.com/questions/12503421/hg-push-error-and-username-not-specified-in-hg-hgrc-keyring-will-not-be-used/14270602#14270602 —Windows LDAP—组用户认证—Mercurial
如果在~/。hgrc (Linux/Unix中用户的主目录)或Windows中的mercury .ini在用户的主目录中,包含,下面的行,如果你做
`"hg clone http://.../.../reponame myremote"`
,那么在每个HTTP回收链接中,用户凭证的提示永远不会超过一次。在~ /。HGRC下的[扩展]一行“mercural_keyring =”或“hgeext。mercural_keyring = /path/to/your/ mercural_keyring .py" ..这里应该有一条线。
[auth]
myremote.schemes = http https
myremote.prefix = thsusncdnvm99/hg
myremote.username = c123456
我试图找出如何设置前缀属性,以便用户可以克隆或执行任何Hg操作,没有用户名/密码提示,而不用担心他在http://..../中提到的…当使用Hg repo链接时,为服务器名。它可以是IP、服务器名或服务器的FQDN