How to configure an SSH proxy server with Squid

Sometimes you can’t connect to an SSH server from your current location. Other times, you may want to add an extra layer of security to your SSH connection. In these cases connecting to another SSH server via a proxy server is one way to get through.

Squid is a full-featured proxy server application that provides caching and proxy services. It’s normally used to help improve response times and reduce network bandwidth by reusing and caching previously requested web pages during browsing.

However for this setup you’ll configure Squid to be used as an SSH proxy server since it’s a robust trusted proxy server that is easy to configure.

Installation and configuration

Install the squid package using sudo:

$ sudo dnf install squid -y

The squid configuration file is quite extensive but there are only a few things we need to configure. Squid uses access control lists to manage connections.

Edit the /etc/squid/squid.conf file to make sure you have the two lines explained below.

First, specify your local IP network. The default configuration file already has a list of the most common ones but you will need to add yours if it’s not there. For example, if your local IP network range is 192.168.1.X, this is how the line would look:

acl localnet src

Next, add the SSH port as a safe port by adding the following line:

acl Safe_ports port 22

Save that file. Now enable and restart the squid proxy service:

$ sudo systemctl enable squid
$ sudo systemctl restart squid

4.) By default squid proxy listens on port 3128. Configure firewalld to allow for this:

$ sudo firewall-cmd --add-service=squid --perm
$ sudo firewall-cmd --reload

Testing the ssh proxy connection

To connect to a server via ssh through a proxy server we’ll be using netcat.

Install nmap-ncat if it’s not already installed:

$ sudo dnf install nmap-ncat -y

Here is an example of a standard ssh connection:

$ ssh

Here is how you would connect to that same server using the squid proxy server as a gateway.

This example assumes the squid proxy server’s IP address is You can also use the host-name or the FQDN of the squid proxy server:

$ ssh -o "ProxyCommand nc --proxy %h %p"

Here are the meanings of the options:

  • ProxyCommand – Tells ssh a proxy command is going to be used.
  • nc – The command used to establish the connection to the proxy server. This is the netcat command.
  • %h – The placeholder for the proxy server’s host-name or IP address.
  • %p – The placeholder for the proxy server’s port number.


There are many ways to configure an SSH proxy server but this is a simple way to get started.

0 (0)
Article Rating (No Votes)
Rate this article
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
OEL 7 – How to disable IPv6 on Oracle Linux 7 – Follow Up
Viewed 7753 times since Wed, Jul 25, 2018
Linux PAM configuration that allows or deny login via the sshd server
Viewed 805 times since Wed, Oct 3, 2018
How to clear swap memory in Linux
Viewed 641 times since Mon, Nov 23, 2020
RHEL: How to change a USER/GROUP UID/GID and all owned files
Viewed 12529 times since Sat, Jun 2, 2018
OpenSSL – sprawdzanie czy klucz pasuje do certyfikatu
Viewed 1516 times since Thu, May 24, 2018
Extending Linux LVM partitions script
Viewed 5289 times since Wed, Feb 6, 2019
How to encrypt a partition using LUKS?
Viewed 917 times since Fri, Jul 13, 2018
RHEL: Force system to prompt for password in Single User mode
Viewed 3569 times since Sat, Jun 2, 2018
RHEL: Handling SCSI disks
Viewed 10084 times since Sun, May 27, 2018
Automatic YUM Updates with Yum-cron
Viewed 9522 times since Fri, Oct 26, 2018