1分钟搞定
# 1. 生成密钥(一路回车)
ssh-keygen -t ed25519
# 2. 复制到服务器
ssh-copy-id root@服务器IP
# 3. 登录(不用密码了)
ssh root@服务器IP
就这么几条命令
| 操作 | 命令 | 说明 |
|---|---|---|
| 生成 | ssh-keygen -t ed25519 | 最新最快算法 |
| 传公钥 | ssh-copy-id user@ip | 自动部署 |
| 登录 | ssh user@ip | 直接进 |
| 权限 | chmod 600 ~/.ssh/id_ed25519 | 私钥必须自己读 |
| 关密码 | /etc/ssh/sshd_config 改 PasswordAuthentication no | 强制用密钥 |
就3个注意点
# 1. 私钥权限必须对
chmod 600 ~/.ssh/id_ed25519
# 2. 服务器公钥权限必须对
chmod 600 ~/.ssh/authorized_keys
# 3. 生产环境一定要关密码登录!
PasswordAuthentication no
故障:还要密码
# 1. 看日志
ssh -vvv user@ip
# 2. 修权限
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# 3. 重传密钥
ssh-copy-id user@ip
ssh-keygen → ssh-copy-id → ssh
发表回复