ff

SSH crib

Port forwarding:



ssh -f -N -L 127.0.0.1:LOCAL_PORT:127.0.0.1:REMOTE_PORT user@host

-f requests ssh to go to background

-N do not execute a remote command, we just want to forward a port, nothing else

-L open local port and forward all traffic to specified remote address/port

127.0.0.1:LOCAL_PORT local port gonna be opened on loopback interface; 127.0.0.1 can be replaced wirth just 127.1

127.0.0.1:REMOTE_PORT ssh will forward all traffic to that address:port

Login using key:



ssh -i /path/to/key user@host


-i path to key file; file should be generated by `ssh-keygen` and copied to remote host using `ssh-copy-id` or manualy

Connection sharing - allows multiple 'virtual' ssh connections to operate via one real tcp session.



Master mode:



ssh -M -S /path/to/socket user@host


-M put ssh client to master mode

-S /path/to/socket master process will create that socket



Controlling existing connection:



ssh -S /path/to/socket -O exit


-O exit ask master process to exit; also some other commands available (such as 'check') - refer to man page

All together:

Start port forwarding session

ssh -f -N -L 127.0.0.1:LOCAL_PORT:127.0.0.1:REMOTE_PORT -i /path/to/key -M -S /path/to/socket user@host

Kill it:

ssh -S /path/to/socket -O exit user@host