SNAP via SSH SOCKS5 Proxy on Ubuntu 24

This guide shows how to download and install Snap packages through an SSH SOCKS5 proxy on Ubuntu 24.04. This is useful when the Ubuntu server has restricted Internet access but can connect to another Linux host with Internet connectivity.

APT and Snap use separate proxy configurations, so configuring a SOCKS proxy for apt does not automatically configure snapd.

Open an SSH SOCKS Proxy

Create a local SOCKS5 proxy on TCP port 1080 through a remote SSH server:

root@kvm-hyp:~# ssh -D 1080 -N -f root@192.0.2.100
root@192.0.2.100's password:

The SSH options are:

  1. -D 1080 - creates a local SOCKS proxy on port 1080
  2. -N - does not start a remote shell
  3. -f - moves the SSH process to the background after authentication

Check the SOCKS Proxy

Verify that SSH is listening locally on port 1080:

ss -ltpn | grep 1080


root@kvm-hyp:~# ss -ltpn | grep 1080
LISTEN 0 128 127.0.0.1:1080 0.0.0.0:* users:(("ssh",pid=1873,fd=5))
LISTEN 0 128 [::1]:1080 [::]:* users:(("ssh",pid=1873,fd=4))
root@kvm-hyp:~#


The expected listener should be on 127.0.0.1:1080.

Configure Snap to Use the SOCKS Proxy

Configure both HTTP and HTTPS Snap traffic to use the local SOCKS5 proxy:

root@kvm-hyp:~# snap set system proxy.http="socks5h://127.0.0.1:1080"
snap set system proxy.https="socks5h://127.0.0.1:1080"

Using socks5h allows hostname resolution to be performed through the SOCKS proxy instead of depending on direct DNS access from the local server.

Check the Snap Proxy Configuration

Verify the currently configured proxy settings:

root@kvm-hyp:~# snap get system proxy
Key Value
proxy.http socks5h://127.0.0.1:1080
proxy.https socks5h://127.0.0.1:1080

Restart snapd

Restart snapd after changing the proxy configuration:

root@q-gr:~# systemctl restart snapd

Install a Snap Package Through the Proxy

Snap commands can now be used normally. In this example, LXD 5.0 is installed from the stable channel:

root@kvm-hyp:~# snap install lxd --channel=5.0/stable
lxd (5.0/stable) 5.0.9-ea18dad from Canonical✓ installed
root@q-gr:~#

The successful installation confirms that snapd can access the Snap Store through the SSH SOCKS proxy.

Use Normal Snap Commands

While the proxy is configured, normal Snap operations use the configured proxy:

snap find PACKAGE_NAME
snap install PACKAGE_NAME
snap refresh
snap list

Disable the Snap Proxy

When direct Internet access is available again, remove both proxy settings:

snap unset system proxy.http
snap unset system proxy.https
systemctl restart snapd

Verify that the proxy settings have been removed:

snap get system proxy

Stop the SSH SOCKS Proxy

Find the SSH process listening on port 1080:

ss -ltpn | grep 1080

Stop the corresponding SSH process when the proxy is no longer needed:

kill <SSH_PID>

Quick Configuration

The complete configuration can be summarized as:

ssh -D 1080 -N -f root@192.0.2.100
snap set system proxy.http="socks5h://127.0.0.1:1080"
snap set system proxy.https="socks5h://127.0.0.1:1080"
snap get system proxy
systemctl restart snapd
snap install PACKAGE_NAME