密钥登录比密码安全得多,还免去每次输密码。强烈建议每台 VPS 都配上。
原理
一对公钥 / 私钥:公钥放服务器,私钥留你本地。登录时用私钥证明身份,密码再也猜不出来。
三步配好
- 本地生成密钥:
ssh-keygen -t ed25519(一路回车,生成~/.ssh/id_ed25519[.pub])。 - 公钥传到服务器:
ssh-copy-id user@你的IP(或手动把.pub内容粘到服务器~/.ssh/authorized_keys)。 - 测试免密登录:
ssh user@你的IP能直接进,就成了。
再关掉密码登录(更安全)
改 /etc/ssh/sshd_config:PasswordAuthentication no → systemctl 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
- Generate a key pair locally:
ssh-keygen -t ed25519(press Enter through the prompts; this creates~/.ssh/id_ed25519[.pub]). - Copy the public key to the server:
ssh-copy-id user@your-server-ip(or manually paste the.pubcontent into~/.ssh/authorized_keyson the server). - 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
sshin 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.
发表回复