SSH Client Usage:

Install on Debian based distro(Usually installed by default):

sudo apt-get install openssh

Generate a SSH Key / Specify type:

ssh-keygen | ssh-keygen -t [key type]

Manually Copy SSH Key to Remote Server:

cat ~/.ssh/[name of key file] | ssh user@hostname “cat – >> ~/.ssh/authorized_keys”

Automatically Install Pub Key to Remote Server:

ssh-copy-id username@remoteserver.com

Connect to a remote machine:

ssh username@remoteserver.com

Add a SSH Agent:

ssh-add

TCP Port Forwarding:

Port Forward a Local Port:

ssh -L [Local Port to connect to]:[Remote Host]:[Port to forward] username@remoteserver.com

Reverse Port Forward to a Remote Machine:

ssh -R [Local Port to connect to]:localhost:[Port to Forward] username@remoteserver.com

then from remoteserver.com

ssh -p [Forwarded Port] username@localhost

Persistant Reverse Port Forward:

while true ; do ssh -R [Local Port to connect to]:localhost:[Port to Forward] username@remoteserver.com ; sleep 60 ; done

SOCKS5 PROXY aka Dynamic Forwarding:

ssh -D [Port to proxy traffic to] username@remoteserver.com

Run a command and exit SSH Shell:

ssh username@remoteserver.com [Command to run]

Forcing a command to run on each connect:

– Edit the ./ssh/authorized_keys file
– Before ssh-rsa type [variable name]=”[command to run]”

Use SCP to copy a file from Local machine to Remote Machine:

scp [/path/to/file.txt] username@remotehost.com:[/path/to/save/dir]

Use SCP to copy from remote machine to local machine:

scp username@remoteserver.com:[/path/to/file.txt] [name of file]

EXAMPLE:

Use SCP to copy from a specific remote directory to specific local directory with different name:

scp username@remoteserver.com:~/Desktop/copyme ~/Documents/newfilename

Use SCP to recursively copy a directory:

scp -r [/path/to/dir] username@remoteserver.com:[/path/to/save/dir]

Use SCP to copy but attempt to keep timestamps/permissions:

scp -rp [/path/to/dir] username@remoteserver.com:[/path/to/save]