Master SSH: Remote Login, Port Forwarding, and Secure Operations

This article introduces SSH, explains its encryption-based login mechanism, demonstrates basic commands for remote access, details port forwarding (local, remote, dynamic) with practical examples, and discusses common security concerns such as man‑in‑the‑middle attacks.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master SSH: Remote Login, Port Forwarding, and Secure Operations

Today we share an introduction to SSH and its usage. Starting from what SSH is, we cover basic usage, remote login, and various port forwarding scenarios.

1. What is SSH?

SSH is a network protocol for encrypted login between computers. In the early Internet, communications were plaintext, exposing data if intercepted. In 1995, Finnish researcher Tatu Ylonen designed SSH to encrypt login information, becoming a fundamental security solution and now a standard configuration on Linux systems.

2. SSH login principle

3. Basic SSH usage

Syntax: ssh -p 22 user@host Parameters:

-p: specify port number.

user: login username.

host: target host.

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

4. SSH remote login example

Two CentOS 6.5 VMs with IPs 192.168.13.135 and 192.168.13.138 are shown.

Check if SSH is enabled:

netstat -ntlp | grep ssh

Connect: ssh -p 22 [email protected] On first login, the host key fingerprint is shown; type yes to continue, then enter the password.

To exit, type exit.

5. SSH port forwarding

SSH can encrypt traffic and also provide port forwarding, forwarding TCP data to a specified host and port while encrypting/decrypting it. Useful when firewalls block certain ports but allow SSH. Two types: local forwarding and remote forwarding.

5.1 Forwarding parameters

-C: compress data
-f: run in background after authentication (often with -N)
-N: do not execute remote command (often with -f)
-g: allow remote hosts to connect to forwarded ports
-L: local_port:dest_ip:dest_port
-D: dynamic port forwarding
-R: remote port forwarding
-T: no TTY allocation (proxy only)
-q: quiet mode

5.2 Local forwarding

Forward a local port to a remote server's port. Format:

ssh -L [local_address:]local_port:target_address:target_port user@target_address

.

Example with two machines A (192.168.13.139) and B (192.168.13.142) where B runs MySQL bound to localhost.

Because B only allows localhost connections, use local forwarding from A:

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

Or shortened: ssh -L 3306:127.0.0.1:3306 [email protected] If usernames match, they can be omitted: ssh -L 3306:127.0.0.1:3306 192.168.13.142 Data flow: A sends to its local 3306, which is forwarded to B's 3306, processed, and returned.

Check forwarding process:

5.3 Remote forwarding

Forward a remote server's port to a local machine. Format:

ssh -R [remote_address:]remote_port:target_address:target_port user@remote_address

.

Example with machines A, B, and a Windows 7 host that cannot directly reach B. Use A to set up remote forwarding so the Windows host can communicate with B.

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

6. SSH remote command execution

Run a command on a remote host: ssh user@host 'command' Examples:

ssh [email protected] 'uname -a'
tar -cz test | ssh [email protected] 'tar -xz'
ssh [email protected] 'netstat -tln | grep 1080'

7. SSH local forwarding (reiterated)

Same as section 5.2, format shown.

ssh -L [local_address:]local_port:remote_address:remote_port remote_user@remote_address

8. SSH remote forwarding (reiterated)

Same as section 5.3, format shown.

ssh -R [remote_address:]remote_port:local_address:local_port remote_user@remote_address

To enable the remote machine to act as a proxy, modify /etc/ssh/sshd_config to set GatewayPorts yes and restart sshd.

vim /etc/ssh/sshd_config
# change GatewayPorts no to yes
service sshd restart

9. SSH dynamic forwarding

Set up a SOCKS proxy:

ssh -D [local_address:]local_port remote_user@remote_address

10. SSH security issues

If an attacker intercepts the login request and spoofs the host's public key, the user may be unable to verify authenticity because SSH keys lack a certificate authority. This enables man‑in‑the‑middle attacks, especially on public Wi‑Fi.

11. Summary

This article covered SSH basics and common practical methods, without deep protocol internals. Further research can explore low‑level implementation and optimization.

Article source: 360 Cloud Computing

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.

LinuxSSHport forwardingRemote Login
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.