VPS设置密钥登录 一键导入公钥到VPS

171 字
1 分钟
VPS设置密钥登录 一键导入公钥到VPS

如果没有密钥 在vps上申请一个 如果有请忽略

申请密钥#

申请密钥对#

Terminal window
ssh-keygen -t ed25519 -a 100

安装公钥#

Terminal window
cat .ssh/id_ed25519.pub >> .ssh/authorized_keys

私钥设置可读权限#

Terminal window
chmod 600 .ssh/id_ed25519

保存好私钥#

id_ed25519

一键导入公钥脚本#

Terminal window
bash <(curl -sL https://raw.githubusercontent.com/leuxinovo/clearvps/main/sshkey.sh) -g github用户名

把公钥导入到GitHub https://github.com/settings/keys 即可使用脚本一键导入公钥到VPS

设置密钥登录#

Terminal window
nano /etc/ssh/sshd_config

进行如下设置: 开启密钥登录:PubkeyAuthentication yes 另外,请留意 root 用户能否通过 SSH 登录: PermitRootLogin yes 当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录: PasswordAuthentication no

最后重启ssh#

Terminal window
systemctl restart ssh

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
VPS设置密钥登录 一键导入公钥到VPS
https://blog.leuxx.de/posts/2/
作者
Leu
发布于
2024-10-09
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
Leu
慢慢折腾,认真记录,每一天都有新的收获
公告
欢迎来到我的博客,随便看看不用客气!
分类
标签
站点统计
文章
35
分类
10
标签
12
总字数
19,835
运行时长
0
最后活动
0 天前
站点信息
构建平台
Cloudflare Pages
博客版本
Firefly v6.13.4
文章许可
CC BY-NC-SA 4.0

文章目录