Linux Hands-On Lab - Create and Use an SSH Tunnel for Network Traffic

Linux Hands-On Lab - Create and Use an SSH Tunnel for Network Traffic

Linux Learning Path for Cloud and DevOps Engineers

📝Introduction

This post explains how port forwarding via SSH (SSH tunnelling) creates a secure connection between your server and a remote machine through which any number of services can be relayed. These are skills that will serve you well in your career as a Linux SysAdmin, Cloud Engineer or DevOps Engineer.

📝Log in to the AWS Management Console

Using your credentials, make sure you're using the right Region. In my case, I am using AWS as my cloud provider and chose us-east-1. However, you are free to choose any cloud provider and create your 2 Linux Server VMs (I am using a CentOS 7 distro) for this hands-on lab.

One of the servers will be our main server and the other our client-server.

Note: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.

You can use link1 and link2 for it.

📝SSH from the CLIENT to the SERVER without a Password

  1. Log in to the CLIENT server.

  2. Generate the key:

     ssh-keygen
    

  3. Press ENTER to accept all defaults when prompted.

  4. Copy the key over to the SSH Tunnel Server server:

     ssh-copy-id <user_name>@<IP_main_server>
    
  5. Type yes to continue.

  6. When prompted, enter the SSH Tunnel Server server's password.

  7. Try logging in to the SSH Tunnel Server server:

     ssh <user_name>@<IP_main_server>
    
  8. Log out of the SSH Tunnel Server server:

     logout
    

📝Verify SSH Tunnel Accessibility

  1. Create the SSH tunnel:

     ssh -f <user_name>@<IP_main_server> -L 2000:<IP_main_server>:80 -N
    
  2. Use the curl command to verify accessibility:

     curl localhost:2000
    
  3. If successful, the output will be Webpage worked

📌Note - At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged if you used a Cloud Provider to provision them.

Congratulations — you have completed this hands-on lab covering the basics of creating a secure connection(SSH tunnelling) between your server and a remote machine.

Thank you for reading. I hope you understood and learned something helpful from my blog.

Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza