The automated setup gave your server an SSH door so you can manage it from your desk.此页面正确锁定了那扇门:按键登录,密码猜测 - 以安全顺序完成,不会将您锁定在自己的服务器之外。
SSH 是几乎所有 Linux 服务器的前门,互联网不断地敲门。自动机器人会在暴露的 SSH 服务器出现后数小时内尝试使用常见密码。密码——即使是一个像样的密码——也是一个可以被猜测、泄露或重复使用的秘密。 SSH 密钥 是一对匹配的密钥:私有的一半永远不会离开您的计算机,公共的一半则存在于服务器上。没有钥匙,就无法进入,也没有什么可猜测的。这是整个强化顺序,按照唯一安全的顺序。
在您的机器上运行它,而不是服务器。如果计算机是共享的,请接受默认位置并在密钥上设置密码。
ssh-keygen -t ed25519 creates a modern, strong key pair.pub 公钥(这一半可以安全地复制到服务器)While password login still works, copy the public half across.在 Linux 和 macOS 上,该工具是内置的; on Windows, the same command ships with the OpenSSH client, or you can paste the public key into the file by hand.
ssh-copy-id [email protected] — 使用您的真实用户名和服务器地址~/.ssh/authorized_keys 中ssh [email protected] 再次登录 — 如果没有询问密码,则密钥有效This is the step that separates a secure server from a locked-out admin.打开新终端窗口并在第一个会话保持打开状态时使用密钥登录。 Only when the second login succeeds do you touch the settings.如果出现任何问题,您的第一次会议仍然可以解决它。
Edit the SSH server settings on the server with sudo nano /etc/ssh/sshd_config, set the two lines below, then restart the service with sudo systemctl restart ssh.在关闭旧会话之前,在另一个新会话中进行测试。
PasswordAuthentication no — 密码不再适用于 SSH;仅钥匙PermitRootLogin prohibit-password — 根本无法通过 SSH 使用密码访问 root 帐户;您以自己的身份登录并使用 sudosudo 是更安全、更负责任的模式保留一种不依赖于 SSH 的本地方式:计算机自己的屏幕和键盘、虚拟机控制台或托管提供商的 Web 控制台。服务器机房和 VPS 面板都提供其中之一。 As long as that exists, even a total SSH mistake is a five-minute fix, not a disaster.
The video’s server is reachable by SSH the moment setup ends. Do this hardening pass right after your first login, while the steps are fresh.
▶️ Watch Full VideoNo, as long as you still have the local console or provider web console. Log in there, add a new public key to ~/.ssh/authorized_keys, and remove the old one. This is why keeping a non-SSH way into the machine matters.
是的。通常的模式是每人一对密钥,在他们管理的每台服务器上使用。如果一台笔记本电脑丢失,您可以从每台服务器上删除该公钥,并且丢失的笔记本电脑的访问权限将在任何地方终止。
It reduces background noise in the logs but adds almost no real security — bots find open ports on any number. Keys plus password login off is the protection that matters. Change the port only if you enjoy quieter logs, and update your firewall rule to match.