什么是安全 Shell 或 SSH?它是如何工作的?

What is Secure Shell or SSH? How does it work?

我正在设置数字海洋水滴。我对网络和系统管理任务的经验很少。

所有关于设置此 Droplet 的文档和教程都强烈建议我设置 SSH 连接。谷歌搜索后,我得到了关于 SSH 是什么的非常广泛的定义和视频,但我似乎无法确切地概念化它是如何工作的。

我什至完全按照一些教程的说明进行操作,所以显然我什至在使用其他 droplet 之前已经完成了此操作。但是,每当我使用 PuTTY 或 WinSCP 登录我的 Droplet 时,我仍然需要提供用户名和密码(即使保存了密码,我也需要输入它才能保存)。

我获得的其他信息:

我只是不太明白我在创建私钥和 public 密钥时在做什么。使用 WinSCP 和 PuTTY 登录我的服务器时,我仍然需要提供我的用户名和密码。难道我做错了什么?关于 SSH;我在做什么?我为什么要这样做?尽管我在登录时仍然需要提供密码,但我这样做是否正确?

如果可能,采取“向 5 岁儿童解释”的方法。

PuTTY 是一个 SSH 客户端,因此您已经在不知不觉中通过 SSH 登录到您的服务器。 Public-私钥只是另一种登录方式(密码登录除外)。它的工作方式是您在家用计算机上生成一个 public/private 密钥对。然后您将 public 密钥提供给服务器,而不是使用您的密码登录(需要您输入密码),您可以使用您的私钥自动登录。如果正确完成,私钥登录也被认为比基于密码的登录更安全。

已经有很多资源可以解释 public-私钥加密的工作原理,下面是我在 Reddit 上找到的一个:

Another way of looking at it is the familiar box analogy. Imagine you want to send a briefcase of information to your friend across the US but need it to be locked so that thieves can't see it. Obviously you can't just put your own lock on there and send it because your friend doesn't have your key to that lock.

The box analogy offers a solution. You put your own lock on the bag and send it to your friend. There, your friend also puts HIS own lock and sends it back. You then unlock your own lock with your key, meaning that the only lock left is your friend's lock. Send it back, and they can easily unlock it and take a look at the information. This is foolproof because a thief would need to know both lock's keys to open the briefcase.

Computing uses a similar model but rather than locks and keys it uses one master lock that can be opened with combinations of three keys, one public key and two private ones that you and your friend each know. Also it takes into account the properties of prime numbers and modular arithmetic. When studying CS, I found that this video helps a lot in understanding how the numberized process of locking and unlocking works.

来源:
https://www.reddit.com/r/explainlikeimfive/comments/1kocba/eli5_rsa_algorithm_and_publicprivate_keys/cbr0l24

此外,如果您想使用 PuTTY 获得 public-私钥登录,这里有一个教程(甚至是特定于 digitalocean 的!):
https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps