linux设置ssh密钥登录

201 字
1 分钟
linux设置ssh密钥登录

ssh配置文件位置:/etc/ssh#

1.修改ssh配置文件:/etc/ssh/sshd_config

参数代码
允许root登录PermitRootLogin prohibit-password
允许密钥登录PubkeyAuthentication yes
禁止密码登录PasswordAuthentication no
定时发送心跳包ClientAliveInterval 30
重试次数ClientAliveCountMax 3
日志文件SyslogFacility AUTH
日志记录等级LogLevel INFO

2.用软件puttygen生成密钥,将公钥并上传至/opt文件夹
3.创建公钥存放路径:mkdir ~/.ssh
4.公钥安装:cat /opt/c01.pub >> ~/.ssh/authorized_keys
5.重启ssh服务:service sshd restart

其他命令#

查看系统登录失败次数:lastb|wc -l
生成密钥对:ssh-keygen -m PEM -t rsa -C "fang523"
生成后的密钥路径:/root/.ssh

甲骨文root登录#

复制opc用户密钥至root文件夹

cp -r /home/opc/.ssh/authorized_keys /root/.ssh/authorized_keys

编辑文件:/root/.ssh/authorized_keys
将ssh-rsa AAAAB3NzaC前面的内容全部删掉
重启ssh服务即可

文章分享

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

linux设置ssh密钥登录
https://www.pidexe.com/posts/linux设置ssh密钥登录/
作者
fang523
发布于
2025-12-01
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
fang523
Hello, I'm fang523.
公告
这是一则公告。
文章目录