Loading... 一键配置密钥登录并禁用密码登录 *【注意保存好公钥和私钥,修改完后不要急于把原密码窗口关闭,先新开一个窗口试试私钥登录,没问题后才关闭原密码登录窗口】* 方法一: 1、 **一键脚本链接** 【需要提前准备好你的密钥对的公钥,没有准备好的可用方法二中的,先生成密钥对】: ``` bash -c "$(curl -L https://raw.githubusercontent.com/wszx123/gongjuxiang/refs/heads/main/authorized_keys.sh)" ``` 2、运行脚本 在 请输入你的 SSH 公钥(以 ssh-rsa 或 ssh-ed25519 开头):这里粘贴你的公钥内容 如果需要恢复密码登录,请执行: ``` bash /root/restore_ssh_password_auth.sh ``` {dotted startColor="#ff6c6c" endColor="#1989fa"/} 方法二: ``` # 1、生成密钥对,邮箱修改为你的邮箱 ssh-keygen -t rsa -b 4096 -C "123456@gmail.com" -f /root/.ssh/sshkey -N "" ``` # 2、存放公钥文件到对应位置并授权,分开进行 ``` cat ~/.ssh/sshkey.pub >> ~/.ssh/authorized_keys ``` ``` chmod 600 ~/.ssh/authorized_keys ``` ``` # 3、查看私钥信息复制到本地(SSH客户端所在的设备上) cat ~/.ssh/sshkey ``` # 4、修改VPS上SSH只接收密钥登录的参数 etc/ssh/sshd_config PermitRootLogin prohibit-password PasswordAuthentication no PubkeyAuthentication yes ChallengeResponseAuthentication no rm -rf /etc/ssh/sshd_config.d/* /etc/ssh/ssh_config.d/* # 5、重启服务器后生效 ``` reboot ``` 最后修改:2025 年 04 月 27 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏
1 条评论
[...]100、BitsFlowCloud PHX 高延迟解决 99、空 98、Claw Cloud 免费容器平台部署webssh教程 97、特殊符号大全【2025年4月29更新】 96、Windows相关【2025年4月29更新】 95、Claw Cloud 免费容器平台部署哪吒面板教程 94、一键配置密钥登录并禁用密码登录 93、bpb面板搭建 92、轻松部署无限节点代理池! 91、C[...]