Latest / CyberSecurity Summary / SSH Mastery: OpenSSH, PuTTY, Tunnels and Keys (IT Mastery)
Transcript
- 0:00Speaker 1: Welcome back to the deep dive. So today we're tackling
- 0:03Speaker 1: secure shell SSH. If you're managing systems remotely, you're definitely
- 0:10Speaker 1: using it, probably open ssh.
- 0:12Speaker 2: Yeah, it's pretty much the standard for anything you and
- 0:15Speaker 2: I X like. But you know, the source material we
- 0:18Speaker 2: look at makes a great point, which is that most
- 0:20Speaker 2: people well they only really scratch the surface, just the
- 0:23Speaker 2: bare minimum functionality, right, and.
- 0:25Speaker 1: There's so much more, especially around you know, doing it securely.
- 0:28Speaker 1: That's what we want to unlock today.
- 0:30Speaker 2: Absolutely true mastery means understanding the security underneath it all.
- 0:34Speaker 1: So our mission for you today, we're going to break
- 0:36Speaker 1: down the core architecture, try to demystify some of that
- 0:40Speaker 1: crypto stuff.
- 0:41Speaker 2: Which you can seem pretty intimidating.
- 0:42Speaker 1: Yeah, definitely, and we'll get into the configurations, the files
- 0:45Speaker 1: you need to know and critically that one habit the
- 0:48Speaker 1: single most important thing you can do to protect yourself
- 0:50Speaker 1: from well the most common network attack.
- 0:53Speaker 2: It's a big one. But maybe a little history first, just.
- 0:56Speaker 1: Quickly, good idea, Yeah, where did SSH come from?
- 0:59Speaker 2: Okay, so back in nineteen ninety five, Tattoo Yelenen He
- 1:03Speaker 2: created it basically because the tools people were using them
- 1:06Speaker 2: telnet rsh are log in.
- 1:08Speaker 1: Oh those were bad sending passwords in the clear.
- 1:11Speaker 2: He totally insecured, just asking for trouble. SSH was built
- 1:14Speaker 2: specifically to create an encrypted, trustworthy channel between two machines
- 1:18Speaker 2: over a network.
- 1:19Speaker 1: And the version everyone uses now open ssh.
- 1:22Speaker 2: That came out of the OPENBSK project, and those folks
- 1:25Speaker 2: have a serious reputation for writing secure code. It's kind
- 1:28Speaker 2: of their thing.
- 1:29Speaker 1: Okay, solid foundation. Then let's dive into the protocol itself.
- 1:33Speaker 1: The main pieces.
- 1:34Speaker 2: Pretty straightforward really. You've got the server side, usually a
- 1:37Speaker 2: program called slewy that's listening for connections.
- 1:40Speaker 1: And then the client side like the slush command on
- 1:42Speaker 1: Linux or.
- 1:42Speaker 2: Mac os exactly, or you know pewdy if you're on Windows.
- 1:46Speaker 2: Microsoft even has its own native client now though I
- 1:48Speaker 2: think it's still experimental.
- 1:49Speaker 1: Right, But now the first big warning sign protocol versions
- 1:54Speaker 1: SSH one versus SSH two.
- 1:56Speaker 2: Ah, yes, this is non negotiable.
- 1:59Speaker 1: What's the rule?
- 2:00Speaker 2: Always always use SSH two, period full stop?
- 2:03Speaker 1: Okay, always SSH two? But why? I mean obviously SSH
- 2:08Speaker 1: one is older? But how bad is it? Really? What's
- 2:10Speaker 1: the risk If say, a server is still consigured to allow.
- 2:14Speaker 2: It, it's incredibly dangerous. The source material literally says it's
- 2:18Speaker 2: barely more secure than unencrypted telnet.
- 2:21Speaker 1: Wow, okay, yeah.
- 2:23Speaker 2: It's not just old. It has fundamental flaws from its
- 2:26Speaker 2: nineteen nineties design, weak key exchange, vulnerable to session hijacking.
- 2:31Speaker 1: So an attacker could actually get into an active session.
- 2:34Speaker 2: They could. They can potentially grab log in credentials, decrypt
- 2:37Speaker 2: your data as it flies by, and maybe the scariest part,
- 2:40Speaker 2: they can inject their own text fuck commands militia shell
- 2:43Speaker 2: command think rmrf something catastrophic and sorted right into what
- 2:47Speaker 2: you thought was a secure.
- 2:48Speaker 1: Session, got terrifying, a total system white command slipped in.
- 2:51Speaker 2: It's the nightmare scenario. And the real danger is how
- 2:54Speaker 2: the connection gets set up. The client and server negotiate
- 2:57Speaker 2: the version. If either one is willing to speak as one,
- 3:00Speaker 2: even if they prefer SSH.
- 3:02Speaker 1: Two, an attacker can force it down.
- 3:04Speaker 2: Exactly a downgrade attack during that initial handshakee. It exploits
- 3:07Speaker 2: that tolerance. Thankfully open ssh itself. It ripped out SSH
- 3:12Speaker 2: one support completely some time ago.
- 3:14Speaker 1: Good, so it forces you onto the modern secure standard. Right.
- 3:17Speaker 2: SSH two has been continuously improved, flaws found and fixed.
- 3:21Speaker 2: It's where you need to be.
- 3:22Speaker 1: Okay, So ssh two it is. Now, let's get into
- 3:25Speaker 1: how SSH two actually protects the data, the cryptography, encryption keys,
- 3:32Speaker 1: the core ideas.
- 3:33Speaker 2: Right, So encryption is basically scrambling turning readable stuff plaintext
- 3:38Speaker 2: into unreadable ciphertext. You need an algorithm like a mathematical
- 3:41Speaker 2: recipe and a.
- 3:41Speaker 1: Key, and open ssh handles the keys, right. It doesn't
- 3:44Speaker 1: let users pick their own password for the encryption itself.
- 3:47Speaker 2: Correct. And that's a deliberate security choice because humans we
- 3:50Speaker 2: are terrible at choosing strong random keys. We pick birthdays,
- 3:53Speaker 2: pet names, predictable stuff exactly. So open ssh generates the
- 3:58Speaker 2: strong cryptographic keys needed. It takes that responsibility away from
- 4:01Speaker 2: the user, which is a good thing here.
- 4:03Speaker 1: You know the algorithms, there are two main types, right,
- 4:06Speaker 1: symmetric and asymmetric. Maybe we can use those analogies from
- 4:08Speaker 1: the source.
- 4:09Speaker 2: Yeah, they're helpful. Symmetric is like think of a simple
- 4:13Speaker 2: kids substitution cipher ABBC, that kind of thing. You use
- 4:17Speaker 2: the same key to lock it, encrypt and unlock it.
- 4:21Speaker 2: Decrypt algorithms like as or symmetric they're very fast, very efficient.
- 4:25Speaker 2: So the catches, how do you securely share that single key?
- 4:28Speaker 2: If I want to talk to your server. How do
- 4:30Speaker 2: I get that secret key over to you without someone
- 4:33Speaker 2: else grabbing it on the way. That's the challenge, right.
- 4:35Speaker 1: Which brings us to asymmetric public key crypto.
- 4:39Speaker 2: Yep. This uses two keys mathematically linked. A public key
- 4:43Speaker 2: you can share with anyone, like putting it on a website,
- 4:46Speaker 2: and a private key you guard with your life.
- 4:48Speaker 1: So I could use your public key to encrypt a
- 4:50Speaker 1: message and only.
- 4:51Speaker 2: My private key can decrypt it. It's very secure for
- 4:54Speaker 2: establishing identity and sharing secrets.
- 4:56Speaker 1: But you said symmetric was fast. Is asymmetric slow?
- 4:59Speaker 2: Much slow? It's computationally intensive. Doing all the encryption and
- 5:02Speaker 2: decryption for an entire SSAF session using just asymmetric keys,
- 5:06Speaker 2: it would be painfully slow, unusable.
- 5:08Speaker 1: Really? Ah okay? So SSH does something clever.
- 5:12Speaker 2: A mix exactly, a hybrid approach. This is the genius part.
- 5:16Speaker 2: When you first connect the client and server use the
- 5:19Speaker 2: server's public key, that's the slow but secure asymmetric part,
- 5:24Speaker 2: just long enough to securely negotiate a brand new temporary symmetric.
- 5:28Speaker 1: Key, the key just for this one session, just for
- 5:31Speaker 1: this session.
- 5:32Speaker 2: Once they've both agreed on that shared secret symmetric key,
- 5:36Speaker 2: they switch all the rest of the communication, all the
- 5:39Speaker 2: commands you type, the file transfers, that's all encrypted using
- 5:43Speaker 2: the fast symmetric key.
- 5:44Speaker 1: The best of both worlds, secure key exchange then fast encryption.
- 5:48Speaker 2: Precisely speed and security.
- 5:50Speaker 1: Okay, that makes sense, but people love the tinker. We
- 5:54Speaker 1: see admins sometimes trying to change the default crypto settings,
- 5:57Speaker 1: maybe choosing different algorithms, thinking they'll get more speeded. What's
- 6:01Speaker 1: the advice there.
- 6:02Speaker 2: Simple, don't do it. Just leave the defaults alone.
- 6:04Speaker 1: Really, why not?
- 6:05Speaker 2: Because the open ssh developers, they are deep cryptography experts.
- 6:09Speaker 2: They chose those defaults, the specific algorithms, the order of preference,
- 6:13Speaker 2: for very good security reasons. They understand the attacks, the weaknesses,
- 6:17Speaker 2: and if I change it, you're basically saying you know
- 6:19Speaker 2: better than them. You might accidentally enable an older weak
- 6:22Speaker 2: or SOFA, or make yourself vulnerable to like a timing attack,
- 6:26Speaker 2: or enable a downgrade attack you didn't intend.
- 6:29Speaker 1: So chasing a tiny speed boost could wreck the actual security.
- 6:32Speaker 2: Completely undermines the whole point of using Ssh in the
- 6:35Speaker 2: first place. Stick with the defaults unless you have an
- 6:38Speaker 2: extremely specific, expert validated reason to change something.
- 6:43Speaker 1: Security first, okay, message re seat, leave the crypto engine alone.
- 6:48Speaker 2: Let's talk configuration files. Then, where do all these settings
- 6:51Speaker 2: actually live? On a typical system.
- 6:54Speaker 1: Right on most Unix like systems, you'll look in the
- 6:57Speaker 1: etceters directory. That's system wide stuff inside there. The service
- 7:01Speaker 1: configuration is in a file called ship config that controls
- 7:04Speaker 1: how the SSH server behaves.
- 7:06Speaker 2: Okay, shits config for the server. What about the client?
- 7:09Speaker 2: If I'm connecting out.
- 7:10Speaker 1: There's a system wide client config two usually its setters
- 7:12Speaker 1: can fig But more importantly for you as a user,
- 7:15Speaker 1: you have your own personal config file in your home directory.
- 7:18Speaker 1: It's home dot shish config and that.
- 7:20Speaker 2: One overrides the system defaults exactly. Let's you set up
- 7:24Speaker 2: custom settings, aliases for hosts, specific keys to use for
- 7:28Speaker 2: certain connections. Very handy.
- 7:31Speaker 1: The syntax looked pretty simple in the source material, like
- 7:34Speaker 1: keyword value so port twenty two or something.
- 7:37Speaker 2: Yeah, it's generally straightforward, and a really nice touch is
- 7:40Speaker 2: that the default config files often have lots of options
- 7:43Speaker 2: already listed, but they're commented out with the hash sign hashtag.
- 7:47Speaker 1: Ah, so they service documentation pretty much.
- 7:50Speaker 2: You can see what's possible, uncomment the line and change
- 7:52Speaker 2: the value if you need to. But there's a really
- 7:55Speaker 2: powerful feature in the servers config stip canfig that we
- 7:58Speaker 2: should highlight what's the match keyword? This thing is amazing
- 8:03Speaker 2: for flexible security.
- 8:04Speaker 1: Match How does it work?
- 8:06Speaker 2: It lets you apply specific configuration lines only if certain
- 8:09Speaker 2: conditions are met, like only for a particular user, or
- 8:12Speaker 2: only for connections coming from a specific IP address range,
- 8:16Speaker 2: or only for members of a certain group.
- 8:17Speaker 1: Well, that sounds useful. Give me an example.
- 8:19Speaker 2: Okay, Let's say you want to disable x eleven forwarding.
- 8:22Speaker 2: That's running graphical apps over SSH for everyone by.
- 8:25Speaker 1: Default security best practice, right right, So you'd put x
- 8:28Speaker 1: eleven forwarding no somewhere near the top exactly.
- 8:31Speaker 2: But then maybe your system administrators, the people in the
- 8:34Speaker 2: wheel group actually need that ability sometimes, so at the
- 8:38Speaker 2: very end of the config file, match blocks always have
- 8:41Speaker 2: to go. At the end, you'd add something like match
- 8:43Speaker 2: group wheel on one line and indented on the next
- 8:46Speaker 2: line x eleven forwarding.
- 8:47Speaker 1: Yes. Ah, so it creates an exception just for.
- 8:51Speaker 2: That group precisely script default then target it overrides based
- 8:55Speaker 2: on user, group, IP address host. Incredibly flexible for setting
- 9:00Speaker 2: up fine grained security policies.
- 9:02Speaker 1: That's really powerful. Okay, speaking of powerful settings, you mentioned
- 9:05Speaker 1: one earlier when we talked about moving away from insecure practices.
- 9:09Speaker 1: The password setting.
- 9:10Speaker 2: Yes, this ties into the whole security deposture. Once you're
- 9:13Speaker 2: set up with user keys, which we'll touch on at
- 9:15Speaker 2: the end. The absolute next step is to go into
- 9:18Speaker 2: your shit canfig and set password authentication no.
- 9:21Speaker 1: Turn off passwords completely completely.
- 9:24Speaker 2: Don't even let the server offer password log in as
- 9:26Speaker 2: an option. This shuts down brute forests password guessing attacks cold.
- 9:31Speaker 2: It's probably the single biggest hardening step you can take
- 9:34Speaker 2: on the server side. After ensuring SSH one.
- 9:37Speaker 1: Is off, okay, makes sense, disable the weaklink. So we've
- 9:41Speaker 1: covered the right version SSH two, the crypto basics hybrid
- 9:44Speaker 1: approach that can fig files, fig choes, can fig match,
- 9:49Speaker 1: and turning off passwords. Now the big one, the single
- 9:52Speaker 1: most vital security habit you.
- 9:54Speaker 2: Mentioned this is it host key verification. This directly tackles
- 9:58Speaker 2: the man in the.
- 9:58Speaker 1: Middle attack that attack again briefly.
- 10:01Speaker 2: Okay, imagine you're trying to connect to your server server
- 10:04Speaker 2: dot example dot com. A bad guy manages to intercept
- 10:07Speaker 2: your network traffic. They pretend to be server dot example
- 10:10Speaker 2: dot com.
- 10:10Speaker 1: So my SSH client connects to the attacker instead of
- 10:12Speaker 1: the real server.
- 10:13Speaker 2: Exactly, and if you then type your password. Well, you've
- 10:16Speaker 2: just given it to the attacker. They can log your credentials,
- 10:18Speaker 2: maybe pass your connection onto the real server so you
- 10:20Speaker 2: don't notice immediately it's bad. How does SSH stop this
- 10:24Speaker 2: with the server's host keys, Remember the asymmetric keys. Every
- 10:30Speaker 2: SSH server has its own unique public private key pair,
- 10:34Speaker 2: often generated when SSH is first installed. Okay, the attacker
- 10:38Speaker 2: can pretend to be your server, but they cannot have
- 10:41Speaker 2: the real server's secret private key. That key never leaves
- 10:46Speaker 2: the legitimate server, so they can impersonate it perfectly cryptographically. No,
- 10:51Speaker 2: they can't complete the secure handshake authentically. This is where
- 10:54Speaker 2: the verification step comes in for you, the user.
- 10:57Speaker 1: Right, because those keys are huge. I don't type in
- 10:58Speaker 1: a public key.
- 10:59Speaker 2: No, you don't. When your SSH client connects to a
- 11:02Speaker 2: server for the very first time, the server presents its
- 11:04Speaker 2: public key. Your client then calculates a shorter, more manageable
- 11:08Speaker 2: summary of that key. That's the fingerprint, like.
- 11:11Speaker 1: SA two two five six hash or something similar.
- 11:13Speaker 2: Usually yeah, something like SUG two five six. These days,
- 11:16Speaker 2: it's maybe forty or fifty characters, almost human readable, as
- 11:19Speaker 2: the source puts it, still random looking, but much shorter.
- 11:22Speaker 1: Than the full key and what am I supposed to
- 11:23Speaker 1: do with this fingerprint?
- 11:24Speaker 2: This is the crucial habit. You need to verify it.
- 11:27Speaker 2: Your assissedmin or the service provider should give you a
- 11:30Speaker 2: list of the correct fingerprints for their servers, maybe on
- 11:33Speaker 2: a secure internal website or in documentation. You manually compare
- 11:38Speaker 2: the fingerprint your client shows you with the known good one,
- 11:41Speaker 2: and if they match, you tell your client, yes, this
- 11:44Speaker 2: is the correct server. The client then saves that server's
- 11:47Speaker 2: public key and its host name IP into your known
- 11:50Speaker 2: hosts file usually home, dot schnown hosts.
- 11:54Speaker 1: It remembers it. So what happens next time I connect?
- 11:57Speaker 2: Next time? The client already knows what key to expect
- 11:59Speaker 2: from ser example dot com. If the server presents the
- 12:03Speaker 2: same key again, the connection just happens transparently, no pumps.
- 12:07Speaker 1: What if it's different? What if the server I connect
- 12:09Speaker 1: to next time presents a key that doesn't match the
- 12:12Speaker 1: one stored in known hosts.
- 12:14Speaker 2: Ah, Now that is the red flag. Your open ssh
- 12:16Speaker 2: client will immediately halt the connection and it will print
- 12:19Speaker 2: a very loud, very scary looking warning the.
- 12:22Speaker 1: All caps one.
- 12:23Speaker 2: Yeah, the source called it scary looking stuff, something like
- 12:26Speaker 2: at warning remote host identification has changed at warn followed
- 12:32Speaker 2: by paragraphs explaining the potential danger of a man in
- 12:35Speaker 2: the middle attack, and it will refuse to connect.
- 12:38Speaker 1: Okay, So the key takeaway for everyone listening. If you
- 12:41Speaker 1: see that massive, scary warning.
- 12:43Speaker 2: Stop, p absolutely stop. Do not under any circumstances, just
- 12:47Speaker 2: bypass the warning and connect anyway.
- 12:49Speaker 1: Why not? What does that warning mean?
- 12:51Speaker 2: It means one of two things. Possibility one, it's legitimate
- 12:54Speaker 2: the sissedmin rebuilt the server or intentionally generated new keys
- 12:58Speaker 2: for some reason. You need to contact them, get the
- 13:01Speaker 2: new correct fingerprint, remove the old key from your known
- 13:04Speaker 2: host file, and then connect and.
- 13:05Speaker 1: Verify the new key, and possibility too.
- 13:07Speaker 2: Possibility two is that you are under attack. Someone is
- 13:10Speaker 2: trying to impersonate your server. If you ignore that warning
- 13:13Speaker 2: and type your password or use your key, you're giving
- 13:16Speaker 2: your credentials directly to the attacker.
- 13:18Speaker 1: So that warning is your lifeline. You must investigate why
- 13:21Speaker 1: the key change before proceeding.
- 13:23Speaker 2: It's the absolute cornerstone of SSH's defense against MITM. Respect
- 13:28Speaker 2: the warning, verify the key always.
- 13:31Speaker 1: Fantastic summary. Okay, so we've covered a lot. SSH two
- 13:34Speaker 1: is mandatory. We understand the hybrid crypto making it fast
- 13:38Speaker 1: and secure. We know where the config files are and
- 13:40Speaker 1: how to use match for flexibility, and we absolutely understand
- 13:44Speaker 1: the critical importance of host key verification.
- 13:46Speaker 2: That nails the core security and transit and server setup.
- 13:50Speaker 1: But it leaves us with one final thought. We secured
- 13:52Speaker 1: the connection, but what about the log in itself?
- 13:55Speaker 2: The authentication right We mentioned turning off passwords, and there's
- 13:59Speaker 2: a big reason our source material talks about these hail
- 14:02Speaker 2: Mary clouds or those massive botnets, huge networks of compromised
- 14:06Speaker 2: computers all over the world, constantly scanning the Internet, hammering
- 14:10Speaker 2: SSAH servers. They just try common user names, route admin
- 14:15Speaker 2: user and common passwords, dictionary words, leaked password.
- 14:18Speaker 1: Lists, just throwing everything at the wall hoping something sticks.
- 14:21Speaker 2: Exactly. It's relentless. Blocking individual IP addresses is pointless. The
- 14:25Speaker 2: attack comes from everywhere. If you rely solely on passwords,
- 14:29Speaker 2: eventually one might get guessed, especially if it's not super complex.
- 14:33Speaker 1: So passwords, even complex ones, are still a major risk
- 14:37Speaker 1: vector just because of this constant automated assault.
- 14:40Speaker 2: They really are, which leads to the ultimate path for
- 14:43Speaker 2: well true SSH mastery and convenience, which is ditching passwords
- 14:48Speaker 2: entirely for login and moving to user keys combined with
- 14:51Speaker 2: the SSAH agent.
- 14:53Speaker 1: Okay, user keys are like host keys, but for me,
- 14:56Speaker 1: the user a public private pair.
- 14:59Speaker 2: Exactly. You general at your own key pair. You put
- 15:01Speaker 2: the public key on the servers you need to access
- 15:04Speaker 2: in your doutch authorized keys file. There you keep the
- 15:06Speaker 2: private key safe on your local machine.
- 15:09Speaker 1: But private keys need protection too.
- 15:10Speaker 2: Write a passphrase, yes, and it should be a long,
- 15:13Speaker 2: strong passphrase, much stronger than a typical login password. But
- 15:17Speaker 2: here's the magic, the SSAH agent.
- 15:19Speaker 1: What does the agent do.
- 15:21Speaker 2: It's a small background program running on your local machine.
- 15:24Speaker 2: When you start your work session, you add your private
- 15:26Speaker 2: key to the agent. It asks for your long strong
- 15:29Speaker 2: passphrase once, just.
- 15:30Speaker 1: Once per session, like once per day when I start.
- 15:32Speaker 2: Work typically Yeah. Once you unlock the key and load
- 15:36Speaker 2: it into the agent's memory, the agent handles authentication for
- 15:39Speaker 2: all subsequent SSH connections without asking you for the passphrase again.
- 15:42Speaker 1: Ah, so I type my super strong passphrase once in
- 15:46Speaker 1: the morning like in slush, into ten different servers throughout
- 15:49Speaker 1: the day without typing any passwords or passphrases at all.
- 15:52Speaker 2: Exactly. It completely defeats the brute force password attacks because
- 15:55Speaker 2: password authentication is off and it makes your life incredibly
- 15:59Speaker 2: convenient because, as you only authenticate once per session to
- 16:02Speaker 2: the agent, high security meets high convenience. That's the goal.
- 16:05Speaker 1: User keys plus the SSAH agent the path to true
- 16:09Speaker 1: SSH mastery. Excellent place to leave it