November 7, 2020 Linux, Application 1 minute, 4 seconds

Basic usage with custom port and custom key

ssh -i ~/.ssh/id_rsa -p PORT USER@HOST

Local port forwarding


For examlpe:

ssh -L localhost:9000:

When you now visit localhost:9000 in your browser you will be tunneled to your machine. There you get the return of the url without actually loging into your machine.

Remote port forwarding


Essentially the other way of local port forwarding for example:

ssh -R 9000:localhost:80

Now if you visit your remote server on port 900 it is directed to your local machine port 80

In sshd_config make sure to add the line GatewayPorts yes.

Run command on host

ssh -i ~/.ssh/id_rsa USER@HOST "sudo apt-get update && sudo apt-get upgrade"

SSH related files

File Purpose
~/.ssh/ User specific ssh settings
~/.ssh/authorized_keys Public keys which are allowed to login as this user
~/.ssh/config User specific ssh config file
~/.ssh/id_* Common prefix for public/private ssh keys
~/.ssh/known_hosts Public host keys known to user
/etc/ssh/ssh_config Global ssh client config
/etc/ssh/sshd_config Global ssh server config

Add authorized key

cat ~/.ssh/ >> ~/.ssh/authorized_keys
#  remotley
ssh-copy-id -i ~/.ssh/id_rsa USER@HOST

Copy files

From host

scp USER@HOST:/path/to/file.txt /tmp/file.txt

To host

scp /tmp/file.txt USER@HOST:/tmp/file.txt


  • -r → copy recursive
  • -P → custom port (note capital P in contrast to ssh)