<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- -*- docbook -*- -->

<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://docbook.org/xml/4.2/docbookx.dtd" []>

<article>

  <articleinfo>

    <title>SSH+SQUID HOWTO</title>

    <author>
      <firstname>Brian</firstname>
      <surname>St. Pierre</surname>
      <affiliation>
        <address><email>SSH+SQUID-HOWTO@bstpierre.org</email></address>
      </affiliation>
    </author>

    <!-- All dates specified in ISO "YYYY-MM-DD" format -->
    <pubdate>2004-07-05</pubdate>

    <!-- Most recent revision goes at the top; list in descending order -->
    <revhistory>
      <revision>
        <revnumber>0.1</revnumber>
        <date>2004-07-05</date>
        <authorinitials>BSS</authorinitials>
        <revremark>First published draft</revremark>
      </revision>
    </revhistory>

    <!-- Provide a good abstract; a couple of sentences is sufficient -->
    <abstract>
      <para>
        This document describes how to set up a secure web proxy using
        SSH and Squid. Such a setup can, among other things, be used to
        circumvent web censorship.
      </para>
      <para>
        This is an early draft. I'm actively seeking feedback. Send
        email to <email>SSH+SQUID-HOWTO@bstpierre.org</email>. Thanks
        in advance for your help.
      </para>
    </abstract>

    <copyright>
      <year>2004</year>
      <holder>Brian St. Pierre</holder>
    </copyright>

    <legalnotice>
      <para>
        Permission to use, copy, modify, and distribute this 
        document for any purpose and without fee is hereby granted,
        provided that the above copyright notice appear in all copies and
        that both that copyright notice and this permission notice appear
        in copies and/or derived works, and that the name of the author not
        be used in advertising or publicity pertaining to distribution of
        the document without specific, written prior permission.
      </para>

      <para>
        THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THE
        INFORMATION CONTAINED IN THIS DOCUMENT, INCLUDING ALL IMPLIED
        WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
        CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
        LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
        CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE
        INFORMATION CONTAINED THIS DOCUMENT.
      </para>

    </legalnotice>

  </articleinfo>

  <sect1 id="intro">
    <title>Introduction</title>

    <para>
      Many organizations (e.g. public libraries, employers) and some
      countries (e.g. Iran, China) have put mandatory web censorship in
      place through the use of filters like Websense or by blocking off
      large portions of the Internet at the (national) network. One way of
      getting around this is by setting up a proxy server that is hosted
      outside the purview of the censoring organization, but is still
      accessible from computers on the censored network.
    </para>
    <para>
      In order for any of this to work, you need:
      <itemizedlist>
        <listitem> 
          <para>A computer that you control (the &quot;server&quot;)
          with an Internet connection hosted outside the censored
          network.</para>
        </listitem>
        <listitem> 
          <para>A static IP address is helpful, but not required.</para>
        </listitem>
        <listitem> 
          <para>It is helpful to be running linux on the server, but
          not required.</para>
        </listitem>
        <listitem> 
          <para>Sufficient administrative privileges on the censored
          computer (the &quot;client&quot;) to be able to install
          software -- or you need to have an SSH client already
          installed on the client.</para>
        </listitem>
      </itemizedlist>
    </para>

    <para>
      Unless specified otherwise, it is assumed that all commands below
      are run as root on the server.
    </para>

    <sect2 id="credits">
      <title>Credits / Contributors</title>

      <para>
        Many thanks to:
      </para>

      <itemizedlist>
        <listitem> 
          <para>Joe DiPerna for providing an outline of how to get
          started.</para>
          <para>Olivier Sessink for creating jailkit.</para>
          <para>The fine folks responsible for openssh and
          squid.</para>
        </listitem>
      </itemizedlist>
    </sect2>

  </sect1>

  <sect1 id="ssh">
    <title>SSH</title>

    <sect2 id="ssh-install">
      <title>Install SSH on the Server</title>
      <para>
        You need to have an SSH server installed on the server. If you are
        running Debian, this is &quot;apt-get install ssh&quot;. If you are running
        something else, install the ssh package from your distribution or go
        to http://www.openssh.com/ and follow the installation instructions.
      </para>
    </sect2>

    <sect2 id="ssh-start">
      <title>Start SSH</title>
      <para>
        You can manually start SSHD by running &quot;/etc/init.d/ssh
        start&quot; (Debian), or &quot;service sshd start&quot; (Red
        Hat). However, this may not cause SSHD to start when the server is
        rebooted. You want SSHD to start every time the server boots. To
        do this, use &quot;ksysv&quot; (Debian) or &quot;chkconfig&quot;
        (Red Hat).
      </para>

      <para>
        On Debian, you may need to remove the file
        /etc/ssh/ssh_not_to_be_started so that SSHD will start.
      </para>
    </sect2>

    <sect2 id="ssh-test">
      <title>Test SSH</title>
      <para>
        It is preferable to test from another machine if you have one
        handy. In a pinch you can test from the same machine. At a prompt,
        run &quot;ssh USERNAME@SERVER-NAME-OR-IP-ADDRESS&quot;. You should
        be prompted for a password, and eventually get a shell prompt.
      </para>
    </sect2>
  </sect1>

  <sect1 id="squid">
    <title>Squid</title>

    <para>
      Squid is a caching web proxy, and is the guts of this setup. It
      is also the most complicated to configure.
    </para>

    <sect2 id="squid-install">
      <title>Install Squid</title>
      <para>
        Install Squid using &quot;apt-get install squid&quot; (Debian)
        or the appropriate command for your distribution. If all else
        fails, go to <ulink
        url="http://www.squid-cache.org/">http://www.squid-cache.org/</ulink>
        and follow the download, installation, and configuration
        instructions there.
      </para>
    </sect2>
    <sect2 id="squid-configure">
      <title>Configure Squid</title>
      <para>
        Squid configuration is a bit hairy. I installed from a Debian package
        and accepted most of the defaults. My changes are outlined here:
      </para>
      <orderedlist>
        <listitem> 
          <para>
            In the ACL section, disable a bunch of ports that are not going
            to be used. I'm only enabling the main SSL and SSH ports, in
            addition to Gopher and FTP. Disable these ports by removing or
            commenting out the corresponding lines.
          </para>
        </listitem>
        <listitem> 
          <para>
            Still in the ACL section, define an acl for
            &quot;our_networks&quot; (this is in the default config I have)
            that is 127.0.0.1/32. This should be the only connection you
            allow -- essentially restricting access to the proxy to the
            local machine.
          </para>
        </listitem>
      </orderedlist>

      <para>
        If you have problems configuring Squid, check the website above.
      </para>

    </sect2>

    <sect2 id="squid-start">
      <title>Start Squid</title>
      <para>
        Starting Squid is eerily similar to starting SSHD see <xref
        linkend="ssh-start" />. The squid startup script is
        &quot;/etc/init.d/squid&quot;.
      </para>
      <para>
        You'll need to restart Squid when/if you make changes to the
        configuration file.
      </para>
    </sect2>

    <sect2 id="squid-test">
      <title>Test Squid</title>
      <para>
        From the server, fire up a browser. Configure the browser to use
        localhost:3128 as a proxy. Go to a few different websites. Check
        the log file (on Debian this is in /var/log/squid/access.log). You
        should see one (possibly several) entry for each web page you
        visited.
      </para>
      <para>
        Celebrate. The hard part is over.
      </para>
    </sect2>

  </sect1>

  <sect1 id="jailkit">
    <title>Jailkit &amp; Users</title>

    <para>
      <blockquote>
        <attribution>From the website
        (http://olivier.sessink.nl/jailkit/)</attribution>
        <para>
          Jailkit is a set of utilities to limit user accounts to specific
          files using chroot() and or specific commands. Setting up a chroot
          shell, a shell limited to some specific command, or a daemon
          inside a chroot jail is a lot easier using these utilities.
        </para>
      </blockquote>
    </para>

    <para>
      Jailkit is highly recommended if you're going to allow other users
      (especially people you've never met and/or don't completely trust). Many
      security holes are only vulnerable to local users. You can reduce your
      exposure to security holes by limiting the programs that your users
      can access. For the purposes of setting up a secure web proxy, they
      really don't need anything beyond a login shell.
    </para>

    <para>
      Jailkit is recommended even if you're just setting this up for
      yourself. In this case, you should create a separate &quot;jailed&quot;
      account for yourself. This limits your exposure in the case where the
      client computer is hijacked or otherwise compromised.
    </para>

    <sect2 id="jailkit-install">
      <title>Install Jailkit</title>
      <para>
        Go to the website referred to above, click the download link, and grab
        the latest source tarball. From a prompt, run the following commands.
        (If you are paranoid, run the first four commands as a non-root user.)
      </para>

      <screen>
        $ tar zxvf jailkit-VERSION.tar.gz
        $ cd jailkit-VERSION
        $ ./configure
        $ make
        $ make install
      </screen>
    </sect2>

    <sect2 id="jailkit-prep">
      <title>Prepare the jail</title>

      <para>
        Follow these instructions <ulink
        url="http://olivier.sessink.nl/jailkit/howtos_chroot_shell.html">at
        the jailkit website</ulink>.
      </para>

      <para>
        Note that &quot;basicshell&quot; is the only required piece of
        initialization. You don't really need to give your users editors or
        anything -- they're just going to be forwarding data via SSH.
      </para>

      <para>
        Run the &quot;jk_check&quot; command when you're done and put this
        command in your crontab as suggested by the instructions referenced
        above.
      </para>
    </sect2>

    <sect2 id="jailkit-accounts">
      <title>Create Additional User Account(s)</title>

      <para>
        If more than one user will be using the proxy and you want to keep them
        separate, you can create an additional user and perform the steps in
        <xref linkend="jailkit-prep" /> again.
      </para>
    </sect2>

    <sect2 id="jailkit-test">
      <title>Test Jailkit</title>

      <para>
        From another machine, run:
        <screen>
          $ ssh -L 3128:SERVER:3128 -l JAILED_USERNAME SERVER
        </screen>
      </para>

      <para>
        You should get a login prompt. Try running &quot;ls&quot; or some
        other command at the prompt. You should get &quot;command not
        found&quot; errors -- which means the jail is working properly.
      </para>
    </sect2>
  </sect1> <!-- end jailkit section -->

  <sect1 id="client">
    <title>Configure the Client</title>


    <sect2 id="client-browser">
      <title>Configure your Browser</title>

      <para>
        Now launch a browser and change your proxy to
        localhost:3128. Detailed instructions for particular browsers are
      below.  </para>
      
      <sect3 id="client-browser-firefox">
        <title>Firefox 0.8</title>
        <orderedlist>
          <listitem>
            <para>
              <menuchoice>
                <guimenu>Tools</guimenu>
                <guimenuitem>Options</guimenuitem>
              </menuchoice>
            </para>
          </listitem>
          <listitem> <para> Select the General tab.  </para> </listitem>
          <listitem> <para> Push the Connection Settings button.  </para> </listitem>
          <listitem> <para> Choose Manual Proxy Configuration.  </para> </listitem>
          <listitem> <para> In the HTTP box, type &quot;localhost&quot;.  </para> </listitem>
          <listitem> <para> In the Port box next to that, type &quot;8118&quot;.  </para> </listitem>
          <listitem> <para> Push OK to close Connection Settings.  </para> </listitem>
          <listitem> <para> Push OK to close Options.  </para> </listitem>
          <listitem> <para> Test the changes by going to http://www.google.com/ </para> </listitem>
        </orderedlist>
      </sect3>
    </sect2>
  </sect1> <!-- end client section -->

<!--
  <sect1 id="troubleshooting">
    <title>Troubleshooting</title>

    <para>
      FIXME
    </para>

    <qandaset>
      <qandaentry>
        <question>
          <para>Question One</para>
        </question>
        <answer>
          <para>Answer One</para>
        </answer>
      </qandaentry>

    </qandaset>
  </sect1>
-->

<!--
  <sect1 id="moreinfo">
    <title>Further Information</title>

    <para>
      FIXME
    </para>
  </sect1>
-->

</article>

