SSH公私钥配置(极简版)


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_configPasswordAuthentication 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-keygenssh-copy-idssh

发表回复

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