Cloud Knowledge

Your Go-To Hub for Cloud Solutions & Insights

Advertisement

Advanced SSH Commands and Techniques

Advanced SSH Commands and Techniques
File System Operations
  • SSHFS: Mount remote file systems locally.
    • Installation:
      • Ubuntu/Debian: sudo apt install sshfs
      • CentOS: sudo yum install fuse-sshfs
Compression
  • Compress Traffic:
    • Use ssh -C hostname or add Compression yes to ~/.ssh/config to enhance performance over slow connections.
    • Example with verbosity: ssh -o "Compression yes" -v hostname.
X11 Forwarding
  • Forward Graphical Applications:

    • Enable: ssh -X user@server or ssh -o ForwardX11=yes user@server.
    • Trusted Forwarding (riskier): ssh -Y user@server.
    • Disable: ssh -x.

Configuration:

Client: Add to ~/.ssh/config

Host *
ForwardAgent yes
ForwardX11 yes

Server: Configure /etc/ssh/sshd_config:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no

Install xauth on the server for X11 authentication :

sudo apt
install xauth  # Ubuntu/Debian
sudo yum
install xauth  # CentOS

SSH Tunneling

Local Port Forwarding:

Route traffic from a local port to a remote machine.

Syntax:

ssh -L local_port:destination:remote_port user@ssh_server

Example:

 ssh root@192.168.0.1 -L 2222:10.0.1.5:3333
Remote Port Forwarding:

Route traffic from a remote port back to a local machine.
Syntax:

ssh -R [remote:]remote_port:destination:destination_port [user@]ssh_server

Example:

ssh -R 8080:192.168.3.8:3030 -N -f user@remote.host

SOCKS Proxy:

Set up a dynamic proxy for traffic.

Syntax:

ssh -D local_port_number user@remote_host

Example with additional options:

ssh -D 6677 -q -C -N -f me@192.168.5.5
ProxyJump (Bastion Host):

Connect to remote hosts via one or more intermediate hosts.

Syntax:

ssh -J proxy_host1 remote_host2

Example (multiple hops):

ssh -J user@proxy_host1:port1,user@proxy_host2:port2 user@remote_host3

Monitoring Traffic with SSH Tunnels

  • Option 1: Install monitoring tools like Wireshark on the router.
  • Option 2: Forward traffic from the router to a monitoring system using SSH tunneling.
  • Leave a Reply

    Your email address will not be published. Required fields are marked *