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.
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 hostRemote 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 modeLocal 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 -pRemote 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@hostSSH 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
