Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config mercurial to push without asking my password through ssh?

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

like image 697
Croplio Avatar asked Aug 29 '10 09:08

Croplio


2 Answers

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.

like image 65
gavinb Avatar answered Nov 04 '22 11:11

gavinb


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!

like image 35
OJ. Avatar answered Nov 04 '22 11:11

OJ.