27.7 rsync Over SSH: Efficient Incremental File Transfers

Right, so you’ve SSH’d into your server. You can run commands, edit files, and feel like a wizard. But what about getting a whole directory of files to or from that remote machine? Your first instinct might be to reach for scp. Don’t get me wrong, scp is a decent enough tool for a quick one-off file copy. But the moment you need to do this more than once, or you need to sync a directory that’s already partially there, scp becomes a blunt instrument. It copies everything, every single time. That’s like packing your entire house into a moving truck just to bring a new book to your bedside table.

27.6 scp: Copying Files Over SSH

Alright, let’s talk about scp. It stands for Secure Copy Protocol, and for years it was the go-to tool for moving files over SSH. It’s simple, it’s ubiquitous, and it gets the job done. You’ll still see it in a million old tutorials and scripts. But before we get into the nitty-gritty, I need to be brutally honest with you: while scp is still perfectly usable, the cool kids (and the security-conscious ones) have largely moved on to rsync over SSH or the modern sftp for interactive sessions. Why? We’ll get to that. But you still need to know scp because it’s everywhere, and sometimes the simplest tool is the right one for a quick job.

27.5 SSH Tunneling and ProxyJump for Bastion Hosts

Right, let’s talk about getting past the gatekeepers. You’ve got a server, let’s call it app-server.internal, sitting pretty on a private network. The only way in is through a single, heavily fortified machine—the bastion host (or jump host). It’s the digital equivalent of a drawbridge. You can’t just SSH directly to your app server; you have to go through the drawbridge first. Now, you could do this manually. SSH to the bastion, then from there, SSH again to the app server. It works, but it’s clunky. You’re juggling two terminals, and doing anything like SCP or forwarding ports becomes a tedious, multi-step nightmare. This is where SSH itself becomes your best friend and automation engineer. We have two primary, brilliant ways to handle this: the older, more versatile Swiss Army knife (-L and -D tunneling) and the newer, cleaner purpose-built tool (-J or ProxyJump).

27.4 Port Forwarding: Local (-L), Remote (-R), and Dynamic (-D)

Alright, let’s talk about SSH port forwarding, which is easily one of the coolest and most “wait, how is that even possible?” features SSH offers. Forget all that “SSH is just for a command line” nonsense. This is where you turn SSH into a digital skeleton key for your network, tunneling traffic through an encrypted pipe to places it was never meant to go. We have three main types: -L (local), -R (remote), and -D (dynamic). I’ll break them down, but first, the universal truth: Forwarding happens on the SSH client machine. Remember that. It’s the machine where you type the ssh command that does the magic.

27.3 ~/.ssh/config: Per-Host Aliases, Keys, and Options

Right, let’s talk about your ~/.ssh/config file. If you’re manually typing ssh -i ~/.some/path/key.pem -p 2222 user@some-long-annoying-hostname.com more than once, you’re doing it wrong. You’re not just wasting keystrokes; you’re inviting carpal tunnel and existential dread. This file is your command-line best friend. It’s where you turn that repetitive, error-prone mess into a simple, elegant ssh my_cool_server. Think of it as a contacts list for your servers. You don’t memorize your friend’s phone number, IP address, and their favorite pizza topping every time you call them. You just tap their name. Your SSH config lets you do the same for machines.

27.2 ssh-copy-id: Deploying Public Keys to Remote Hosts

Right, so you’ve generated your SSH key pair. You’ve got this lovely little id_ed25519.pub file sitting there, full of promise. It’s like a high-tech key you just cut. But a key is useless unless you actually put it in the lock on the other side. That’s where ssh-copy-id comes in. It’s the part of the process where you stop admiring your own cleverness and actually get to log in without a password.

27.1 SSH Key Generation: ssh-keygen and Key Types (RSA, Ed25519)

Right, let’s talk about the one thing standing between you and a password-free, secure connection to your servers: your SSH key pair. This isn’t just a password replacement; it’s a fundamental shift from “something you know” to “something you have.” We’re generating cryptographic proof of your identity. And we’re going to do it the right way, not the way some dusty old tutorial from 2005 tells you to. The workhorse for this job is ssh-keygen. It doesn’t have a flashy GUI because it doesn’t need one. It’s a precision instrument, and by the time we’re done, you’ll know how to wield it.

— joke —

...