Foundations of Python Network Programming

(WallPaper) #1
289

Chapter 16

Telnet and SSH


If you have never read it, then you should brew some of your favorite coffee, sit down, and treat yourself to
Neal Stephenson’s essay “In the Beginning... Was the Command Line” (William Morrow Paperbacks, 1999).
You can also download a copy from his web site in the form (appropriately enough) of a raw text file at
http://www.cryptonomicon.com/beginning.html.
The command line is the topic of this chapter. It covers how you can access it over the network, together with
enough discussion about its typical behavior to get you through any frustrating issues that you might encounter while
trying to use it.
Happily enough, the old-fashioned idea of sending simple textual commands to another computer will, for many
readers, be one of the most relevant topics of this book. The main network protocol discussed—the Secure Shell
(SSH)—seems to be used everywhere to configure and maintain machines of all kinds.
When you get a new account at a web hosting company and you have finished using its fancy control panel to set
up your domain names and list of web applications, the command line is then your primary means of installing and
running the code behind your web sites.
Virtual servers, or physical servers from companies like Rackspace and Linode, are almost always administered
through SSH connections.
If you build a cloud of dynamically allocated servers using an API-based virtual hosting service like Amazon AWS,
you will find that Amazon gives you access to your new host by asking you for an SSH key and installing it so that you
can log into your new instance immediately and without a password.
It is as if once early computers became able to receive text commands and return text output in response, they
reached a kind of pinnacle of usefulness that has yet to be improved upon. Language is the most powerful means
humans have for expressing meaning, and no amount of pointing, clicking, or dragging with a mouse has ever
expressed even a fraction of what can be communicated when you type, even in the cramped and exacting language
of the Unix shell.


Command-Line Automation


Before getting into the details of how the command line works and how you can access a remote command line over
the network, note that there are more specific tools you might want to examine if your specific goal is to perform
remote system administration. In order of increasing sophistication, here are three directions in which the Python
community has taken remote automation:



  1. Fabric lets you script actions to be performed over SSH connections to your servers, but
    besides making you operate at the fairly low level of specific commands, it supports only
    Python 2 at the moment (see http://www.fabfile.org/)..)

Free download pdf