生成 SSH 密钥对时,确保使用强密码保护私钥。
确保私钥文件的权限设置正确,防止未授权访问。
600
:
chmod 600 ~/.ssh/id_rsa ssh-agent
可以简化私钥的使用,避免每次连接时都需要输入密码。
将公钥添加到目标主机的 ~/.ssh/authorized_keys
文件中,启用公钥认证。
ssh-copy-id
命令将公钥复制到目标主机:
ssh-copy-id user@target_host~/.ssh/authorized_keys
文件中:
cat ~/.ssh/id_rsa.pub | ssh user@target_host "cat >> ~/.ssh/authorized_keys"为了提高安全性,建议禁用密码认证,仅使用公钥认证。
/etc/ssh/sshd_config
文件,禁用密码认证:
PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no定期轮换 SSH 密钥可以减少长期使用同一密钥带来的安全风险。
~/.ssh/authorized_keys
文件中,然后删除旧的公钥。
cat ~/.ssh/new_id_rsa.pub | ssh user@target_host "cat >> ~/.ssh/authorized_keys" ssh user@target_host "sed -i '/old_public_key/d' ~/.ssh/authorized_keys"原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有