This guide describes how to set up an SSH tunnel between two computers via an external gateway.
A basic understanding of the ssh command (particularly the -R and -p options) is sufficient for following this guide.
The corkscrew utility is used to bypass internal firewalls that block direct SSH access to a VPS over the standard port 22.
This can be useful in corporate environments where the IT or security department restricts outbound connections.
Security note: For better protection against unauthorized access, configure SSH key‑based authentication and disable password logins. This is not covered in detail here.
graph LR
A["Home PC"] <-- port 6666 --> B(VPS) <--> C(Office proxy) <-- port 6644 --> D[Work PC]
n1["Gremlins
o(Tヘoω・ヘ(_|ωノ・(シ||д|_ ̄)▽┌┴┴┌_φ∵∧σ(͡° ͜ ʖ͜ ⊙)"]
n1@{ shape: hex} -- attack on VPS --> B
style n1 fill:#FF9D80
Hosts:
-
Home PC
home_iphome_user
-
VPS
vps_ipvps_user
-
Work PC
work_ipwork_user
Ports:
- Random port 1 — 6666
- Random port 2 — 6644
-
On the Home PC, open a reverse SSH tunnel (keep it running):
home@ssh -R 6666:localhost:22 vps_user@vps_ip -
From the VPS, connect to the Home PC:
vps@ssh -CX home_user@localhost -p 6666
-
Install corkscrew on the Work PC: https://github.com/bryanpkc/corkscrew
-
Configure SSH on the Work PC, replacing
INTERNAL_PROXY_IPandINTERNAL_PROXY_PORTwith your office proxy details:host name_vps HostName vps_ip Port 443 User vps_user ProxyCommand /usr/local/bin/corkscrew INTERNAL_PROXY_IP INTERNAL_PROXY_PORT %h %p host name_home HostName localhost User home_user Port 6666 ProxyJump name_vps
-
Connect to the VPS:
work@ssh -CX name_vps
-
Ensure the Home PC has the reverse tunnel running:
home@ssh -R 6666:localhost:22 vps_user@vps_ip -
From the Work PC:
work@ssh -CX name_home
-
On the Work PC, start a reverse SSH tunnel:
work@ssh -R 6644:localhost:22 name_vps -
From the Home PC:
home@ssh -CX vps_user@vps_ip
vps@ssh -CX work_user@localhost -p 6644
graph LR
A["Home PC"] --> B(VPS)
From the Home PC:
home@ssh vps_user@vps_ip
Verify that networking, package management, and basic tools are working:
vps@
apt update
vps@apt install mc htopIf your VPS provider gives you only the
rootaccount:sudo useradd vps_user sudo usermod -aG sudo vps_user sudo usermod -aG root vps_userDisable direct root login in
/etc/ssh/sshd_config:PermitRootLogin noRestart the SSH service:
sudo service ssh restart
graph LR
A["Home PC"] <-- port 6666 --> B(VPS)
A VPS cannot initiate an SSH connection to a home machine with a private (NAT) IP address. Instead, the Home PC must establish a reverse tunnel to the VPS.
-
Open Remonte tunnel on Home PC (should be running):
home@ssh -R 6666:localhost:22 vps_user@vps_ip -
Connect to Home PC from VPS:
vps@ssh -CX home_user@localhost -p 6666 -
Keep the tunnel alive automatically:
autossh ins't standart util
home@sudo apt install autossh
home@autossh -f -N -R 6666:localhost:22 vps_user@vps_ip
graph LR
A(VPS) <--> B[corkscrew] <--> C[Work PC]
If the office network restricts outbound SSH:
-
Install corkscrew:
https://github.com/bryanpkc/corkscrew -
Configure SSH on the Work PC:
host name_vps HostName vps_ip Port 443 User vps_user ProxyCommand /usr/local/bin/corkscrew INTERNAL_PROXY_IP INTERNAL_PROXY_PORT %h %p
-
Connect:
work@ssh -CX name_vps
graph LR
A["home PC"] <-- port 6666 --> B(VPS) <--> C(рабочий proxy) <-- port 6644 --> D[work PC]
-
On the Work PC:
work@ssh -R 6644:localhost:22 name_vps -
On the Home PC:
home@ssh -CX vps_user@vps_ip
vps@ssh -CX work_user@localhost -p 6644
host name_vps
HostName vps_ip
User vps_user
host name_vps_R
HostName vps_ip
User vps_user
RemoteForward 6666 localhost:22
host *
ForwardX11 yes
Compression yeshost name_vps
HostName vps_ip
Port 443
User vps_user
ProxyCommand /usr/local/bin/corkscrew 192.168.172.129 3128 %h %p
host name_vps_R
HostName vps_ip
User vps_user
RemoteForward 6644 localhost:22
host name_home
HostName localhost
User home_user
Port 6666
ProxyJump name_vps
host *
ForwardX11 yes
Compression yeshost name_home
HostName localhost
User home_user
Port 6666
host name_work
HostName localhost
User work_user
Port 6644
host *
ForwardX11 yes
Compression yessudo apt install autossh
export AUTOSSH_DEBUG=1
export AUTOSSH_GATETIME=0
export AUTOSSH_PORT=20037
autossh -f -N vps_user@vps_ip -R 6666:127.0.0.1:22