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.10 | Log in to a server. |
ssh -p 2222 jernej@server.example.com | Log in on a different port. |
exit Ctrl+D | Log 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.10 | Linux/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 no | In /etc/ssh/sshd_config on the server, after the key works – no more password logins. |
sudo systemctl restart ssh | Apply 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 22 | A 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-backup | Copy 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 nas | Open the server's port 80 as localhost:8080 on your computer. |
ssh -L 5432:localhost:5432 nas | Reach a database that only listens on the server itself. |
Sessions that survive (tmux)
tmux new -s work | Start a named session on the server. |
Ctrl+B then D | Detach – the programs keep running after you log out. |
tmux attach -t work | Come back to it later, even from another computer. |
tmux ls | List sessions. |