ssh tunnel

SSH,

Syntax

ssh -L|-R|-D [bind_address:]port:host:hostport [user@]hostname

Parameters

ParametersDescriptionExamplesLevel
-L (→) ssh -L 8080:localhost:80 user@host Common
-R (→) ssh -R 9090:localhost:3000 user@host Common
-D (SOCKS ) ssh -D 1080 user@host Common
-N command, ssh -N -L 8080:localhost:80 user@host Common
-f ssh -fN -L 8080:localhost:80 user@host Advanced
-g ssh -g -L 8080:localhost:80 user@host Advanced

Examples

ssh -N -L 3307:localhost:3306 user@db-server
3307 MySQL 3306, mysql -h 127.0.0.1 -P 3307

SOCKS

ssh -D 1080 -N user@proxy-server
SOCKS5 127.0.0.1:1080

ssh -R 8080:localhost:3000 user@public-server
public-server:8080 3000

ssh -fN -L 5433:db-internal:5432 user@bastion
-f, -N shell,

Common Errors

bind: Address already in use, lsof -i :
channel 0: open failed: connect failed: Connection refused, and

Tips

Related Commands