SSH extended guide

This is a small Guide with some useful SSH features. Beginning with the setup of your ssh-keys.

ssh authentication keys

Generate Keyfiles

ssh-keygen -t ed25519 -C "mail@domain.com"

-C option sets an optional comment, like name or email

Copy your public key to remote.com

ssh-copy-id user@remote.com
ssh remote.com

ssh forwarding

Forward localhost:8000 to remote.com:9000

#requires `GatewayPorts clientspecified` in `/etc/ssh/sshd_config`
ssh -R 9000:localhost:8000 remote.com

Forward remote.com:3306 (mysql) to localhost:8000

ssh -L 8000:localhost:3306 remote.com

Remote forwarding aka SOCKS5 Proxy

ssh -D 8000 remote.com

ssh server restrictions

The ~/.ssh/authorized_keys file can contain options to restrict access. The options are only applied to the public key they are prefixed with.

restric port forwarding

no-port-forwarding ssh-rsa AAAB3Nza...Q9DXw==

run command at login

command="echo No, ${SSH_ORIGINAL_COMMAND} - not working." ssh-rsa AAAB3Nza...9DXw==
$ ssh remote.com -- cat ~/some_file
'No, cat /var/www/some_file - not working.'

ssh escape

ssh allows for escape sequences after a newline

[ENTER] ~?

gives you a list of options.

[ENTER] ~C

enters you into ssh command line, where you can forward ports with an already established connection or cancel forwarding at any time.

If your session is not responsive you can terminate the session with [ENTER] ~.