Online Book Reader

Home Category

Mercurial_ The Definitive Guide - Bryan O'Sullivan [44]

By Root 938 0
URL) is check your firewall configuration.

By default, hg serve listens for incoming connections on port 8000. If another process is already listening on the port you want to use, you can specify a different port to listen on using the -p option.

Normally, when hg serve starts, it prints no output, which can be a bit unnerving. If you’d like to confirm that it is indeed running correctly, and find out what URL you should send to your collaborators, start it with the -v option.

Using the Secure Shell Protocol

You can pull and push changes securely over a network connection using the Secure Shell (ssh) protocol. To use this successfully, you may have to do a little bit of configuration on the client or server sides.

If you’re not familiar with ssh, it’s the name of both a command and a network protocol that let you securely communicate with another computer. To use it with Mercurial, you’ll be setting up one or more user accounts on a server so that remote users can log in and execute commands.

(If you are familiar with ssh, you’ll probably find some of the material that follows to be elementary in nature.)

How to Read and Write ssh URLs

An ssh URL tends to look like this:

ssh://bos@hg.serpentine.com:22/hg/hgbook

The ssh:// part tells Mercurial to use the ssh protocol.

The bos@ component indicates what username to log into the server as. You can leave this out if the remote username is the same as your local username.

The hg.serpentine.com gives the hostname of the server to log into.

The :22 identifies the port number to connect to the server on. The default port is 22, so you only need to specify a colon and port number if you’re not using port 22.

The remainder of the URL is the local path to the repository on the server.

There’s plenty of scope for confusion with the path component of ssh URLs, as there is no standard way for tools to interpret it. Some programs behave differently than others when dealing with these paths. This isn’t an ideal situation, but it’s unlikely to change. Please read the following paragraphs carefully.

Mercurial treats the path to a repository on the server as relative to the remote user’s home directory. For example, if user foo on the server has a home directory of /home/foo, then an ssh URL that contains a path component of bar in fact refers to the directory /home/foo/bar.

If you want to specify a path relative to another user’s home directory, you can use a path that starts with a tilde character followed by the user’s name (let’s say otheruser), like this.

ssh://server/~otheruser/hg/repo

And if you really want to specify an absolute path on the server, begin the path component with two slashes, as in this example.

ssh://server//absolute/path

Finding an ssh Client for Your System

Almost every Unix-like system comes with OpenSSH preinstalled. If you’re using such a system, run which ssh to find out if the ssh command is installed (it’s usually in /usr/bin). In the unlikely event that it isn’t present, take a look at your system documentation to figure out how to install it.

On Windows, the TortoiseHg package is bundled with a version of Simon Tatham’s excellent plink command, and you should not need to do any further configuration.

Generating a Key Pair

To avoid the need to repetitively type a password every time you need to use your ssh client, I recommend generating a key pair.

* * *

Key pairs are not mandatory


Mercurial knows nothing about ssh authentication or key pairs. You can, if you like, safely ignore this section and the one that follows until you grow tired of repeatedly typing ssh passwords.

* * *

On a Unix-like system, the ssh-keygen command will do the trick.

On Windows, if you’re using TortoiseHg, you may need to download a command named puttygen from the PuTTY website to generate a key pair. See the puttygen documentation for details of how to use the command.

When you generate a key pair, it’s usually highly advisable to protect it with a passphrase. (The only time that you might not

Return Main Page Previous Page Next Page

®Online Book Reader