SSH 密钥登录怎么配?比密码更安全How to Set Up SSH Key Login: More Secure Than Passwords

作者:

密钥登录比密码安全得多,还免去每次输密码。强烈建议每台 VPS 都配上。

原理

一对公钥 / 私钥:公钥放服务器,私钥留你本地。登录时用私钥证明身份,密码再也猜不出来。

三步配好

  1. 本地生成密钥ssh-keygen -t ed25519(一路回车,生成 ~/.ssh/id_ed25519[.pub])。
  2. 公钥传到服务器ssh-copy-id user@你的IP(或手动把 .pub 内容粘到服务器 ~/.ssh/authorized_keys)。
  3. 测试免密登录ssh user@你的IP 能直接进,就成了。

再关掉密码登录(更安全)

/etc/ssh/sshd_configPasswordAuthentication nosystemctl restart sshd

提醒

  • 私钥绝不外传,泄露等于交出服务器。
  • 关密码登录前,确认密钥能登上,否则会被锁在外面。
  • Windows 用 PowerShell 自带 ssh 或 PuTTY 都行。

配合 安全加固 效果更好。

还没挑好机器?去 库存监控 按线路 / 地区筛选在售机型。

Key-based authentication is far more secure than passwords and eliminates the need to type a password every time. Highly recommended for every VPS you set up.

How It Works

A public/private key pair: the public key lives on the server, the private key stays on your local machine. When you log in, the private key proves your identity — no password to guess or brute-force.

Three Steps to Set It Up

  1. Generate a key pair locally: ssh-keygen -t ed25519 (press Enter through the prompts; this creates ~/.ssh/id_ed25519[.pub]).
  2. Copy the public key to the server: ssh-copy-id user@your-server-ip (or manually paste the .pub content into ~/.ssh/authorized_keys on the server).
  3. Test passwordless login: run ssh user@your-server-ip — if you get in without a password prompt, you’re done.

Then Disable Password Login (Even More Secure)

Edit /etc/ssh/sshd_config: set PasswordAuthentication no, then run systemctl restart sshd.

Reminders

  • Never share your private key — losing it means losing the server.
  • Before disabling password login, confirm you can log in with the key, or you’ll lock yourself out.
  • On Windows, the built-in ssh in PowerShell or PuTTY both work fine.

Combine this with a security hardening guide for best results.

Haven’t picked a VPS yet? Visit the stock monitor to filter available plans by route / region.

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注