Running the Server

Ordinarily, an SSH server is invoked when the host computer is booted, and it is left running as a daemon. This works fine for most purposes. Alternatively, you can invoke the server manually. This is helpful when you’re debugging a server, experimenting with server options, or running a server as a nonsuperuser. Manual invocation requires a bit more work and forethought but might be the only alternative for some situations.

Most commonly, a computer has just one SSH server running on it. It handles multiple connections by spawning child processes, one per connection.[43] You can run multiple servers if you like: for example, two copies of sshd listening on different TCP ports, or even several versions of sshd at once.

5.1.1 Running sshd as the Superuser

The SSH server is invoked by simply typing its name:

    $ sshd

The server automatically runs in the background, so no ampersand is required at the end of the line.

To invoke the server when the host computer boots, add appropriate lines to an appropriate startup file on your system, such as /etc/rc.local on Linux. For example:

    # Specify the path to sshd.
    SSHD=/usr/local/sbin/sshd
    # If sshd exists and is executable, run it and echo success to the system console.
    if [ -x "$SSHD" ]
    then
      $SSHD && echo 'Starting sshd'
    fi

Both OpenSSH and Tectia come with a startup or boot script (i.e., a System-V-style init control script) found in the appropriate directory for each Unix variant. For Linux, for example, the scripts are /etc/init.d/sshd ...

Get SSH, The Secure Shell: The Definitive Guide, 2nd Edition 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.