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
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' firstname.lastname@example.org
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. 192.0.0.1 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' email@example.com -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 127.0.0.1:80.
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 firstname.lastname@example.org:~/TO_FILE_DIRECTORY
Instead of using ssh, this time you are using the scp command. the FROM_FILE_DIRECTORY can be something like ./myfile.zip 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!
Wrong content? Edit on Github.