Index

SSH

SSH connections keep alive:
sudo vi /etc/ssh/ssh_config
ServerAliveInterval 60
connect to remote server
ssh [user]@example.com
connect on a different port
ssh -p 62775 [user]@example.com
invoke a script located on the remote server
ssh user@server '/path/to/script.sh'
invoke a local script on the remote server
ssh user@server bash < [script]
execute remote command
ssh user@server "sudo /opt/scripts/doSomething.sh magic"

tunneling / proxying

use ssh connection as a socks proxy
ssh -D [local_port] [user]@[host]
use ssh connection as a socks proxy no shell
ssh -N -D [local_port] [user]@[host]
forward local port to specified remote port on host
sudo ssh -L [local_port]:localhost:[remote_port] [user]@[host]
forward local port to specified remote port on host no shell
sudo ssh -N -L [local_port]:localhost:[remote_port] [user]@[host]
use gateway server to ssh into another server
ssh -J [gateway] [destination]

ssh keys

generate private and public key
ssh-keygen
copy local ssh key to server for key based authentication
ssh-copy-id [user]@[host]
or manually paste public key into remote config file
vi ~/.ssh/authorized_keys

secure copy (scp)

copy file to remote
scp /tmp/file.zip yourdomain.com:/path/to/file.zip
copy remote directory
scp -r [user]@example.com:/data/upload /data/
connect to a different port
scp -P 62775 [from] [to]
download a file from host [target] tunnelling the call through host [gateway]
ssh -L [port]:[target]:22 [gateway_user]:[gateway]
scp -P [port] [target_user]@[gateway]:[file] .

running ssh commands on multiple hosts at once (untested & needs arguments)

parallel-ssh

mounting remote filesystems

mounting a remote directory onto the local filesystem
sshfs [user]@[host]:[remote_path] [mountpoint]
unmounting the remote directory
umount [mountpoint]

hostfile

config file location
~/.ssh/config
sample entry
Host [alias]
	HostName example.com
	User [user]
	IdentityFile ~/.ssh/[key]
	Port 22
	ForwardX11 no
	ForwardAgent no
launching an entry from this file
ssh [alias]
show launch menu containing all aliases
rofi -show ssh
more examples
https://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/
man page
https://linux.die.net/man/5/ssh_config