Cheat Sheets

JPNAS.NET / Cheat Sheets

🔐 SSH & Remote Work

Logging in to servers, keys instead of passwords, copying files, tunnels and sessions that survive a lost connection. OpenSSH is built into Linux, macOS and Windows 10/11.

Open in the interactive Cheat Sheets

Connecting

ssh jernej@192.168.1.10Log in to a server.
ssh -p 2222 jernej@server.example.comLog in on a different port.
exit Ctrl+DLog out.
Enter ~ .Close a frozen SSH session (three keys one after another).

Keys instead of passwords

ssh-keygen -t ed25519 -C "jernej@laptop"Make a key pair. Protect it with a passphrase.
ssh-copy-id jernej@192.168.1.10Linux/macOS: copy your public key to the server.
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh jernej@192.168.1.10 "cat >> ~/.ssh/authorized_keys"Windows PowerShell: the same without ssh-copy-id.
PasswordAuthentication noIn /etc/ssh/sshd_config on the server, after the key works – no more password logins.
sudo systemctl restart sshApply the change (the service is called sshd on Fedora). Keep the old session open until the new login works!

~/.ssh/config – shorter commands

Host nas HostName 192.168.1.10 User jernej Port 22A short name for a server. Then ssh nas is enough.

Copying files

scp file.txt nas:/home/jernej/Copy a file to the server.
scp -r nas:/var/www/site ./site-backupCopy a folder from the server to here.
rsync -avh --progress folder/ nas:/backup/folder/Copy only what changed. The / at the end of folder/ matters.
rsync -avh --delete folder/ nas:/backup/folder/Make the target the same as the source – deletes what is not in the source.

Tunnels

ssh -L 8080:localhost:80 nasOpen the server's port 80 as localhost:8080 on your computer.
ssh -L 5432:localhost:5432 nasReach a database that only listens on the server itself.

Sessions that survive (tmux)

tmux new -s workStart a named session on the server.
Ctrl+B then DDetach – the programs keep running after you log out.
tmux attach -t workCome back to it later, even from another computer.
tmux lsList sessions.