0
0
Linux CLIscripting~15 mins

SSH tunneling (port forwarding) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
SSH Tunneling (Port Forwarding)
📖 Scenario: You work in a company where you need to securely access a database server that is only accessible from the company network. You want to use SSH tunneling (port forwarding) to connect to the database from your local machine.
🎯 Goal: Learn how to create a local SSH tunnel that forwards a local port to a remote database server port through an SSH server.
📋 What You'll Learn
Create a variable with the SSH server address
Create a variable with the remote database port
Write the SSH command to create a local port forwarding tunnel
Display the SSH command output or confirmation
💡 Why This Matters
🌍 Real World
SSH tunneling is used to securely access remote services like databases or web servers that are behind firewalls or private networks.
💼 Career
Many IT and DevOps roles require setting up SSH tunnels to securely connect to remote resources without exposing them publicly.
Progress0 / 4 steps
1
Set SSH server address
Create a variable called ssh_server and set it to user@example.com which is the SSH server address.
Linux CLI
Need a hint?

Use single quotes to assign the string value to the variable.

2
Set remote database port
Create a variable called remote_db_port and set it to 5432, which is the port number of the remote database server.
Linux CLI
Need a hint?

Assign the port number as an integer without quotes.

3
Write SSH local port forwarding command
Create a variable called ssh_command that stores the SSH command string to forward local port 6543 to the remote database port 5432 on localhost through the SSH server stored in ssh_server. Use the syntax: ssh -L 6543:localhost:5432 user@example.com.
Linux CLI
Need a hint?

Use double quotes and variable substitution with ${variable} inside the string.

4
Display the SSH command
Write a command to print the value of the ssh_command variable to show the full SSH tunneling command.
Linux CLI
Need a hint?

Use echo "$ssh_command" to display the command.