Debian 系统 Telnet 安全配置指南
一 安全原则与总体建议
二 安装与最小配置
sudo apt update && sudo apt install telnetsudo apt install telnetd(常见由 xinetd 或 inetd 托管)service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
server_args = -h
log_on_failure = USERID
only_from = 192.168.1.0/24
interface = 192.168.1.10
}
sudo systemctl restart xinetdtelnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetdALL: ALL;/etc/hosts.allow 写入 in.telnetd: 192.168.1.0/24sudo ufw allow from 192.168.1.0/24 to any port 23;或默认拒绝:sudo ufw deny 23/tcpsudo iptables -A INPUT -p tcp --dport 23 -s 192.168.1.0/24 -j ACCEPT;其余来源 DROPsudo tail -f /var/log/auth.log三 用户权限与认证加固
/etc/securetty 中移除或注释与 telnet 相关的终端行(如 pts/*),使 root 无法通过 Telnet 登录。/etc/security/access.conf 添加-:ALL EXCEPT your_admin_user:ALL
/usr/sbin/nologin 在 /etc/shells 中):sudo usermod -s /usr/sbin/nologin baduser/etc/pam.d/telnet 中使用 pam_access.so 实施来源与用户级策略,例如:account required pam_access.so
access.conf 达到“来源网段 + 允许用户”的双重约束。四 加密替代与迁移步骤
sudo apt update && sudo apt install openssh-serversudo systemctl start ssh && sudo systemctl enable sshPermitRootLogin noPasswordAuthentication no,PubkeyAuthentication yesAllowUsers your_admin_usersudo systemctl restart ssh五 关闭 Telnet 与应急关闭
sudo systemctl stop xinetd && sudo systemctl disable xinetdsudo systemctl stop inetd && sudo systemctl disable inetdsudo systemctl stop telnet.socket && sudo systemctl disable telnet.socketsudo ufw deny 23/tcpsudo iptables -A INPUT -p tcp --dport 23 -j DROP/etc/hosts.deny 写入 ALL: ALL,并确保 /etc/hosts.allow 无 in.telnetd 放行规则ss -ltnp | grep :23 或 nc -vz <host> 23,应显示关闭或拒绝。