上一篇 下一篇 分享链接 返回 返回顶部

Centos密钥登录SSH-命令方法/宝塔方法

发布人:五洛雲網維GuanT 发布时间:2025-04-26 18:19 阅读量:526

在 CentOS(或其他 Linux 系统)中,使用 SSH 密钥登录时,​​RSA​​ 和 ​​Ed25519​​ 是两种常见的密钥类型,它们的核心区别在于算法实现、安全性和性能。以下是两者的对比:

 

​​RSA​​:传统算法,依赖长密钥(如4096位)保证安全,兼容性强,适合旧系统。

​​Ed25519​​:基于椭圆曲线,密钥更短(256位),安全性更高(抗量子)、性能更快,需较新系统支持。

​​建议​​:优先选Ed25519(高效安全),旧设备用RSA。

本次环境系统为:centos7.6使用Ed25519算法开启密钥登录。

下载SSH工具地址:https://www.bt.cn/new/product_pc.html

一:宝塔方法

二:命令方法

1.centos7生成SSH密钥命令:ssh-keygen -t ed25519 -C "admin@wuluoyun.com"

2.将公钥添加到授权文件:cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys

3.开启 SSH 密钥登录

sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config

sed -i 's/PubkeyAuthentication no/PubkeyAuthentication yes/g' /etc/ssh/sshd_config

关闭 SSH 密码登录(可选开启/关闭,建议关闭)

sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config

sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config

4.查询SSH密钥服务:grep -E '^PubkeyAuthentication' /etc/ssh/sshd_config

查询SSH密码服务:grep -E '^PasswordAuthentication' /etc/ssh/sshd_config

5.重启 SSH 服务:systemctl restart sshd(执行完SSH命令需要重启一下SSH服务)

6.查询私钥密钥命令:cat ssh/id_ed25519

7.下载私钥密钥命令:如图路径/root/.ssh

8.测试使用SSH密钥登录:

注:关闭密码登录前,必须测试私钥密钥是否可正常登录系统!!!

 

其他教程:

新增SSH私钥密钥(命名id_ed25519_testssh):ssh-keygen -t ed25519 -C "www@test.com" -f ~/.ssh/id_ed25519_testssh

删除SSH私钥密钥(命名id_ed25519_testssh):rm ~/.ssh/id_ed25519_testssh ~/.ssh/id_ed25519_testssh.pub

 

目录结构
全文