
王.W
适用场景:
- 本文档基于Win11实践,其它设备同理
- 本地开发(Git / PyCharm / Docker)
- 懒猫微服(NAS / 私有云)
- SSH 免密登录 + Docker / PostgreSQL 远程开发

Win11 (PyCharm / Git)
│
│ SSH (key only)
▼
懒猫微服(sshd)
│
│ Docker Bridge
▼
pg-docker / PostgreSQL
👉 数据库 不暴露公网端口,只走 SSH 本地转发
ssh-keygen -t ed25519 -f ~/.ssh/id_github_ed25519 -C "github-wtj-king"
ssh-keygen -t ed25519 -f ~/.ssh/id_lazycat_ed25519 -C "lazycat-wtj-king"
# github添加公钥
cat ~/.ssh/id_github_ed25519.pub # 内容复制到GitHub →Settings → SSH and GPG keys → New SSH key
# 将公钥添加到懒猫
ssh-copy-id -i ~/.ssh/id_lazycat_ed25519.pub root@name.heiyu.space
vim ~/.ssh/config # 添加SSH config 示例
~/.ssh/
├── id_github_ed25519 # GitHub 专用
├── id_lazycat_ed25519 # 懒猫微服专用
├── config
# ===== 全局默认 =====
Host *
AddKeysToAgent yes
UseKeychain yes
# ===== 懒猫微服 =====
Host lazycat
HostName name.heiyu.space
User root
IdentityFile ~/.ssh/id_lazycat_ed25519
IdentitiesOnly yes
AddressFamily any
# ===== GitHub =====
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_github_ed25519
IdentitiesOnly yes
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_github_ed25519
ssh-add ~/.ssh/id_lazycat_ed25519
ssh -T git@github.com # 输入 yes 看到:Hi wtj-king! You've successfully authenticated
ssh lazycat # 直接登录,无密码 ✅
/etc/ssh/sshd_config
Include /etc/ssh/sshd_config.d/*.conf
sshd_config.d 中的文件 后加载、可覆盖主配置/etc/ssh/sshd_config.d/lzc.confPermitRootLogin yes
ListenAddress 0.0.0.0
ListenAddress fc03:xxxx::xxxx
含义:
👉 不能直接改它(会被系统还原)
nano /etc/ssh/sshd_config.d/99-wtj-hardening.conf
# ==== WTJ SSH Hardening ====
# 禁止密码登录
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
# root 仅允许 key 登录
PermitRootLogin prohibit-password
# 仅允许本地端口转发(PyCharm / pg-docker)
AllowTcpForwarding local
GatewayPorts no
# 降低暴力破解风险
MaxAuthTries 3
LoginGraceTime 30s
MaxSessions 3
# 限制可登录用户
AllowUsers root
Missing privilege separation directory: /run/sshd
/run 是 tmpfs(内存目录)/run/sshdmkdir -p /run/sshd
chmod 755 /run/sshd
然后再次检查:
sshd -t
1. 保留当前 SSH 会话
2. mkdir /run/sshd
3. sshd -t # 必须无输出
4. systemctl restart ssh
5. 新窗口测试登录
sshd -T | grep -E "permitrootlogin|passwordauthentication|allowtcpforwarding"
你应看到:
permitrootlogin prohibit-password
passwordauthentication no
allowtcpforwarding local
👉 这比看配置文件 更权威
优势:
sshd -Tsshd_config.d✅ 个人 / 家用 NAS:S 级
✅ 远程开发环境:生产可用
✅ SSH 被扫描:几乎无收益
本文档可作为:
- 个人运维笔记
- 懒猫 / NAS 安全基线
- 以后重装系统的标准模板
评论
0暂无评论