💾 Archived View for her.st › blog › ssh-is-power.gmi captured on 2023-05-24 at 18:00:14. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

let's just jump right in.

port forwarding

You might want to host a gameserver so you can play with your friend, or show a client your progress by giving him

access to your local webserver - but you are behind a firewall and don't want to or simply can't forward the ports?

SSH can do it. All you need is a cheap server, like from my hosting service and you can use it to forward ports in a single line.

remote forwarding

For said scenarios above, where you run a server locally and want to expose it to the internet, like a webserver or gameserver

running on port 8080

ssh -R 8080:127.0.0.1:8080 user@hostname.her.st

now you can give hostname.her.st:8080 (or the server IP) to your friend or client, and ssh will tunnel everything to your local machine.

local forwarding

now let's say you want to access a mysql server that's running on your server. You can't connect to it over the internet

MySQL will only listen on 3306 locally, and be firewalled off. Still want to connect your dev environment to it? SSH can do it.

ssh -L 3306:127.0.0.1:3306 user@hostname.her.st

if you now connect your mysql client to 127.0.0.1:3306, you will actually connect to hostname.her.st:3306 (and you get encryption for free)

appendix

The format is defined like that:

8080:127.0.0.1:8080

RemotePort (on the server):Destination (your computer):LocalPort(on your computer)

disconnected - no problem

if you have access to screen on the server, use ssh -t user@hostname.her.st screen -RR and you will create a screen immediately

upon login, or reattach to the last one if it exists. Similar behavior can be achieved with tmux. if your internet connection

goes down or indeed even if you close the terminal, your stuff will keep running.

mount remote filesystem locally

tired of scp yet? try sshfs

run a speedtest

yes | pv | ssh remote_host "cat >/dev/null"

and it it's good enough (internet: >= 5mb/s, local: 35mb/s)

mount it

sshfs	-o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user user@hostname.her.st:/	/mnt/server-root

now you can just cp and mv to /mnt/server-root to upload files. you can treat it like any folder.

oh and visual studio code

You can literally let vscode ssh into your server, install itself there, copy all your local settings and extensions over and have vsc run on your server instead

so your development environment is always the same, no matter what device you use. All your files will be stored on the server too, so no more forgetting your files either. I've been using it for months and love it.

vscode remote ssh

Comments

View/Write Comments