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
  1. The ssh:// part tells Mercurial to use the ssh protocol.

  2. 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.

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

  4. 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.

  5. 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 ...

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.