ssh登录显示系统信息
[ding@ArchLinux templates]$ ssh hs
Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-55-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
You have new mail.
Last login: Sat Feb 28 13:41:11 2026 from 116.171.246.84
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🖥 Hostname : isrv.cn
🐧 OS : Ubuntu 24.04 LTS
🔧 Kernel : 6.8.0-55-generic
⏱ Uptime : up 6 days, 9 hours, 2 minutes
📊 Load : 0.03, 0.03, 0.00
🌐 IPv4 : 192.168.72.90
💽 Disk / : 22G/40G (57%)
🧠 Memory : 1.8Gi/1.9Gi
🔁 Swap : 0B/1.0Gi
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Last login: root pts/0 116.171.246.84 Sat Feb 28 13:41 - 19:01 (05:20)
root@isrv:~#
✅ 一、统一「专业级」登录信息(推荐主用)#
👉 不依赖发行版,不被系统升级覆盖
1️⃣ 创建统一 MOTD 脚本#
cat >/etc/profile.d/00-sysinfo.sh <<'EOF'
#!/bin/bash
# 只在 SSH 登录时显示
[[ -n "$SSH_CONNECTION" ]] || return
# 基础信息
HOSTNAME=$(hostname)
OS=$(grep PRETTY_NAME /etc/os-release 2>/dev/null | cut -d= -f2 | tr -d '"')
KERNEL=$(uname -r)
UPTIME=$(uptime -p)
LOAD=$(uptime | awk -F'load average:' '{print $2}')
IPV4=$(hostname -I 2>/dev/null | awk '{print $1}')
# 资源
DISK=$(df -h / | awk 'NR==2{print $3 "/" $2 " (" $5 ")"}')
MEM=$(free -h | awk '/Mem/{print $3 "/" $2}')
SWAP=$(free -h | awk '/Swap/{print $3 "/" $2}')
# 登录信息
LAST_LOGIN=$(last -n 2 "$USER" | sed -n '2p')
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
printf " 🖥 Hostname : %s\n" "$HOSTNAME"
printf " 🐧 OS : %s\n" "${OS:-Unknown}"
printf " 🔧 Kernel : %s\n" "$KERNEL"
printf " ⏱ Uptime : %s\n" "$UPTIME"
printf " 📊 Load : %s\n" "$LOAD"
printf " 🌐 IPv4 : %s\n" "${IPV4:-N/A}"
printf " 💽 Disk / : %s\n" "$DISK"
printf " 🧠 Memory : %s\n" "$MEM"
printf " 🔁 Swap : %s\n" "$SWAP"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
[[ -n "$LAST_LOGIN" ]] && echo " Last login: $LAST_LOGIN"
echo
EOF赋权:
chmod +x /etc/profile.d/00-sysinfo.sh✅ 效果
- SSH 登录自动显示
- root / 普通用户都生效
- Ubuntu / CentOS / Rocky / 精简云镜像都能用
✅ 二、Ubuntu 风格「完整 system-info MOTD」(可选)#
👉 如果你想 像第一台 Ubuntu 那样
2️⃣ 安装并启用 update-motd(Ubuntu / Debian)#
apt update
apt install -y update-motd landscape-common确认 PAM:
grep pam_motd /etc/pam.d/sshd应包含:
session optional pam_motd.so motd=/run/motd.dynamic
session optional pam_motd.so noupdate测试:
run-parts /etc/update-motd.d/📌 如果你想「精简 Ubuntu 的 MOTD」#
禁用某些脚本即可:
chmod -x /etc/update-motd.d/91-release-upgrade
chmod -x /etc/update-motd.d/10-help-text✅ 三、SSH 登录信息执行顺序(你关心的原理图)#
SSH 登录
↓
/etc/pam.d/sshd
↓
pam_env.so
pam_motd.so
↓
/etc/update-motd.d/* (Ubuntu)
↓
/etc/profile
↓
/etc/profile.d/*.sh ← ★我们刚才放的脚本
↓
~/.bashrc
↓
Shell Ready📌 所以你现在的脚本位置是“最稳妥层级”
✅ 四、顺手把 SSH 安全 & 信息也一起优化(强烈建议)#
你日志里已经出现:
There were 34197 failed login attempts4️⃣1 显示失败登录次数(已包含在脚本里)#
4️⃣2 立刻加固 SSH(不影响你现有登录)#
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak编辑:
vim /etc/ssh/sshd_config建议最小安全集(你这种公网服务器很适合):
PermitRootLogin prohibit-password
PasswordAuthentication no
MaxAuthTries 3
LoginGraceTime 20重载:
systemctl reload sshd(可选)自动封 IP(fail2ban)#
apt install -y fail2ban
systemctl enable --now fail2ban✅ 五、关于你看到的「量子算法警告」#
WARNING: connection is not using a post-quantum key exchange✔ 正常
✔ 不影响安全
✔ 服务端 OpenSSH 版本较旧