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
Log in to the
CLIENT
server.Generate the key:
ssh-keygen
Press ENTER to accept all defaults when prompted.
Copy the key over to the
SSH Tunnel Server
server:ssh-copy-id <user_name>@<IP_main_server>
Type
yes
to continue.When prompted, enter the
SSH Tunnel Server
server's password.Try logging in to the
SSH Tunnel Server
server:ssh <user_name>@<IP_main_server>
Log out of the
SSH Tunnel Server
server:logout
📝Verify SSH Tunnel Accessibility
Create the SSH tunnel:
ssh -f <user_name>@<IP_main_server> -L 2000:<IP_main_server>:80 -N
Use the
curl
command to verify accessibility:curl localhost:2000
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