惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - Nihaorz

告别闪烁,拥抱流畅:在 Windows Terminal 中完美配置 Cygwin 环境 Nginx 透明代理 + 自动回源存储:访问即缓存,落盘即文件 创建 docker ipvlan,让 docke 容器获取独立ip 电犀牛 R68s iStoreOS 2.5G 网口速率优化 解决 openwrt ssh 命令行终端 home、end 键不可用问题 一键添加视频封面脚本 ffmpeg 转码参数 docker save 远程 ssh 主机直接 load,不产生本地文件 AutoHotKey 脚本 - win10 自动连接无线显示器 SSH 登录/退出实时监控脚本 OpenClaw 安装部署,配置 deepseek curl 断点续传下载 debian iso 镜像下载地址 linux 安装 zerotier,加入网络 基于 Fail2ban 的 SSH 入侵自动反制方案 memc - 基于 shell 的交互式清理内存脚本 基于 Fail2ban 的 OpenWRT SSH 入侵自动反制方案 Linux Screen 命令速查 使用 ofelia 在 docker 容器中执行计划任务 linux 磁盘挂载示例
ssh 配置密钥登录,关闭密码登录
Nihaorz · 2026-03-04 · via 博客园 - Nihaorz

公钥登录

# 创建登录密钥
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519_linux_login

# 复制公钥到服务器
ssh-copy-id -i ~/.ssh/id_ed25519_linux_login.pub root@192.168.100.102

# 测试密钥登录
ssh -i ~/.ssh/id_ed25519_linux_login root@192.168.100.102

一定要在测试密钥登录成功之后再做下面的操作

关闭密码登录

#!/bin/bash
[ "$EUID" -ne 0 ] && { echo "需要root权限"; exit 1; }

SSHD_CONFIG="/etc/ssh/sshd_config"

# 严格检查:文件必须存在
[ ! -f "$SSHD_CONFIG" ] && { echo "错误: $SSHD_CONFIG 不存在"; exit 1; }

# 清理旧配置
sed -i '/^\s*PasswordAuthentication\s/d' "$SSHD_CONFIG"
sed -i '/^\s*ChallengeResponseAuthentication\s/d' "$SSHD_CONFIG"
sed -i '/^\s*PubkeyAuthentication\s/d' "$SSHD_CONFIG"
sed -i '/^\s*UsePAM\s/d' "$SSHD_CONFIG"

echo >> "$SSHD_CONFIG"
echo '# 调整配置' >> "$SSHD_CONFIG"
# 追加安全配置
{
    echo "PasswordAuthentication no"
    echo "ChallengeResponseAuthentication no"
    echo "PubkeyAuthentication yes"
    echo "UsePAM yes"
} >> "$SSHD_CONFIG"

重启 ssh 服务

有些系统是重启 sshd

posted @ 2026-03-04 12:33  Nihaorz  阅读(26)  评论()    收藏  举报