Connect to OpenVPN server over SSH Tunnel (using Terminal on Mac)

In this article, we'll explain how to connect to your private OpenVPN server over SSH Tunnel to encapsulate the transmitted data for added security to your connection.

 

Requirements:

  1. Linux VPS or Dedicated Server with SSH access enabled.
  2. OpenVPN Server installed on your VPS/Dedicated server.
    For more about OpenVPN server installation on CentOS / RHEL / Almalinux / RockyLinux, Check this Github repo or follow this article.
    OpenVPN server must run on TCP protocol and port 443 is recommended.
  3. Mac OS machine
  4. Terminal app
  5. OpenVPN Connect app installed on your Mac.

Ignore the requirement #2 if you already have the .ovpn profile ready.

 

Prepare the VPN profile

After you've installed OpenVPN server using the installation script mentioned above, the installation script will create the .ovpn profile on the server. Copy this profile to your PC (the profile must have ".ovpn" extension).

(Assuming that the VPN server IP is 40.40.40.40 and OpenVPN Server is listening to TCP port 443)
  1. Open the downloaded OpenVPN profile on your Mac with a text editor
  2. Replace the line remote 40.40.40.40 443 with remote 127.0.0.1 8585 
    (127.0.0.1 is the localhost IP, and 8585 is the local port "you can use any available port number").
  3. Save the profile.

 

Import Profile to OpenVPN Connect App

  1. Open OpenVPN Connect App
  2. Import the edited .ovpn profile
  3. Proceed to the next step.

Open Terminal Window on Mac

  1. Open Terminal App.
  2. Run this command to initiate an SSH connection with port forwarding enabled
    ssh -v -N -L 127.0.0.1:8585:<VPN_SERVER_IP>:<VPN_PORT> root@<SSH_SERVER_IP>​

    replace <VPN_SERVER_IP> with the VPN server IP, in out example it's 40.40.40.40
    replace <VPN_PORT> with the VPN port, in out example it's 443
    replace <SSH_SERVER_IP> with the IP address of an SSH-accessible server. This may be the same as the VPN server IP if SSH access is available, or any other server you can access via SSH.
    replace root with the SSH user.

  3. Enter the SSH password when prompted.
  4. Now you've an active SSH Connection with Port forwarding enabled on local port 8585.

 

Securely connect to VPN over SSH Tunnel

Now you've SSH Connection open on Terminal, leave it open all the time while you're using the VPN.

  1. Back to OpenVPN Connect App
  2. Select the VPN profile and Connect.
  3. You're now connected over the SSH tunnel!

 

 

  • openvpn, ssh, linux, mac
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

I receive HostRound emails in my SPAM box, how to fix this?

We do our best to improve email deliverability, however, some of our emails may land in your...

What is a Ransomware?

Ransomware is a type of malicious software, or malware, designed to deny access to a computer...

How to clear Google Chrome DNS cache

To clear Google Chrome DNS Cache Type this in the address bar  chrome://net-internals/#dns...

How to connect to FTP server using FileZilla

We're going to explain how to connect to FTP server using FileZilla FTP Client. Before you start...

Chrome is showing weird font/ hand writing font/ script font on some websites

If you visit some websites and see weird font displayed on the website instead of the original...