SSH Connect to Linux Server from a Mac using SOCKS5 Proxy


I’ve been spending a lot of time lately in setting up on-premises Linux Servers. There are a lot of reasons why you would like to SSH to a Linux server such as checking configuration files, copying files, or even port forwarding.

Just open your MacOS terminal and the command to ssh to a Linux Server is as simple as:

ssh user@host or ssh michael@

However, where it gets tricky is when you need to use a proxy such as SOCKS5 in order to access that Linux server from your MacOS machine.


I ended up using ssh-connect which can easily be installed using Homebrew.

brew install connect

Useful Commands

Set SOCKS5 Password

Now in order to use a proxy such as SOCKS5, it’s best to export the password prior to the SSH command, otherwise you will end up typing this password repeatedly.


SSH session

Now to start an SSH session to that Linux server, use the following command:

ssh -o 'ProxyCommand=/usr/local/bin/connect -S michael-px@sshproxydomain​:1080 %h %p' michael-vm@

michael-px is my user under the SOCKS5 proxy. The password was set from above “SOCKS5_PASSWORD”. 1080 is the port used by the SOCKS5 proxy.

michael-vm is my user inside the Linux VM. is the IP address of the VM.

Port Forwarding

To port forward from the Linux server to your localhost (MacOS), use the following command:

ssh -o 'ProxyCommand=/usr/local/bin/connect -S michael-px@sshproxydomain​:1080 %h %p' michael-vm@ -L 8888:localhost:80

It’s very similar to the SSH session command but added with -L 8888 to point that it’s the “localhost:8888” of the server and it forwards the traffic to the MacOS' localhost:80 or

This is very useful whenever you are debugging or testing a deployed service or website inside that Linux VM.

Copy files via SSH

To copy files from your MacOS machine to the Linux server, use the following command:

scp -o 'ProxyCommand=/usr/local/bin/connect -S michael-px@sshproxydomain:1080 %h %p' FROM_FILE_DIRECTORY michael-vm@

Instead of using ssh, this time you are using the scp command. the FROM_FILE_DIRECTORY can be something like ./ and the TO_FILE_DIRECTORY can be /mnt/hdd1/file-drops

Note that it could also work the other way around (from Linux Server to MacOS local machine).


The world of Linux and command lines are wonderful and very flexible. There are more things you can do once you’re inside the server. Happy SSH-ing!