Master SSH: Remote Login, Port Forwarding, and Secure Tunneling Explained

This guide introduces SSH, explains its encryption-based login mechanism, demonstrates common commands for remote access, local and remote port forwarding, dynamic tunneling, and highlights security risks such as man‑in‑the‑middle attacks, providing practical examples for Linux environments.

ITPUB
ITPUB
ITPUB
Master SSH: Remote Login, Port Forwarding, and Secure Tunneling Explained

What Is SSH?

SSH (Secure Shell) is a network protocol that provides encrypted login between computers. It was created in 1995 by Tatu Ylonen to replace plaintext communication, and it is now the default remote‑access method on most Linux systems.

SSH Login Principle

Basic SSH Usage

Typical syntax: ssh -p 22 user@host Parameters:

-p: specify port (default 22)

user: remote username

host: remote host address

If the port is 22, it can be omitted: ssh user@host If the local username matches the remote username, the username can also be omitted:

ssh host

Remote Login Example

Two CentOS 6.5 VMs with IPs 192.168.13.135 and 192.168.13.138 are used. To verify SSH is running: netstat -ntlp | grep ssh Connect from one host to the other: ssh -p 22 [email protected] On first connection the client shows the host key fingerprint and asks for confirmation; typing yes accepts it. After entering the password the session is established. Exit with exit.

SSH Port Forwarding

SSH can forward TCP ports, useful when firewalls block direct access. Two types exist: local forwarding and remote forwarding.

Forwarding Options

-C  : compress data
-f  : run in background (often with -N)
-N  : do not execute remote command
-g  : allow remote hosts to connect to forwarded ports
-L  : local port forwarding
-R  : remote port forwarding
-D  : dynamic (SOCKS) forwarding
-T  : disable pseudo‑tty allocation
-q  : quiet mode

Local Forwarding

Forward a local port to a remote service. Example: forward local port 3306 to a MySQL server on a remote host.

ssh -L 127.0.0.1:3306:127.0.0.1:3306 [email protected]

If the local address is omitted, the command can be shortened: ssh -L 3306:127.0.0.1:3306 [email protected] If usernames match, the user part can be omitted as well: ssh -L 3306:127.0.0.1:3306 192.168.13.142 After setting up the tunnel, the MySQL client connects to the local port as if the database were on the same machine:

bin/mysql -h127.0.0.1 -uroot -p

Remote Forwarding

Forward a port on the remote machine back to the local network. Example:

ssh -R 127.0.0.1:80:10.18.78.135:80 [email protected]

This makes the remote host listen on its port 80 and forward traffic to the specified local address.

Dynamic Forwarding

Creates a SOCKS proxy that forwards any TCP connection through the SSH tunnel:

ssh -D 1080 user@host

SSH Remote Command Execution

Run a command on a remote host without opening an interactive shell: ssh user@host 'command' Examples:

Check OS type: ssh [email protected] 'uname -a' Copy a directory: tar -cz test | ssh [email protected] 'tar -xz' Test if a port is listening:

ssh [email protected] 'netstat -tln | grep 1080'

Security Considerations

Because SSH keys are self‑signed, an attacker who intercepts the connection can present a forged key (a man‑in‑the‑middle attack). Users must verify host key fingerprints, especially on first use, to avoid credential theft.

Conclusion

The article covered the basic concepts of SSH, common usage patterns such as remote login, local and remote port forwarding, dynamic tunneling, and highlighted potential security pitfalls. Deeper protocol internals and performance optimizations are beyond its scope.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxnetwork securitySSHport forwardingRemote Login
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.