Linux SOCKS Proxy for SSH

How To Setup

  • In one SSH session run:
    • ssh -N -D 7080
      • If you SSH to localhost (IP Address on port 7080, this command forwards that port/request to
      • -N – No Command will be sent once the tunnel is up
        • You do not want an open session where commands can run
      • -D – Specifies the port for your localhost to listen on
    • Enter Password at prompt
    • if successful, there will be no prompt
      • Sort of like it is hanging to log in

How to Use

Use SSH -o Option

  • open up a new terminal session
  • Run the following command:
ssh -o ProxyCommand='nc --proxy-type socks4 --proxy %h %p'
  • This will uses socks version 4
  • --proxy your connection to on port 7080
  • Substitute %h %p with

Create a SSH Config File

  • open a terminal session
  • run nano ~/.ssh/config
  • paste in the following
    • it will automatically forward connections to the above proxy server for:
    • any hostname ending with or any IP address starting with 192.168.
      • but the SSH command will have to have the hostname not an IP address
    • But will proxy not to or
Host * ! !
                ProxyCommand nc --proxy-type socks4 --proxy %h %p

Host 192.168.*
                ProxyCommand nc -X 4 -x localhost:7180 %h %p
  • press CTRL + X to save
  • press Y
  • Now you can test a connection

About Daniel Fredrick

Technology enthusiast, Programmer, Network Engineer CCIE# 17094

View all posts by Daniel Fredrick →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.