在Linux中禁用Telnet服務可以通過以下步驟完成。請注意,這些步驟可能會因不同的Linux發行版而略有不同。
systemctl(適用于使用systemd的系統)大多數現代Linux發行版(如Ubuntu、CentOS 7/8、Debian等)都使用systemd來管理服務。
sudo systemctl stop telnet.socket
sudo systemctl disable telnet.socket
service(適用于使用SysVinit的系統)一些較舊的Linux發行版可能仍然使用SysVinit來管理服務。
sudo service xinetd stop
sudo service xinetd disable
你也可以通過配置防火墻來阻止Telnet連接。
iptables如果你使用的是iptables,可以添加規則來阻止Telnet端口(默認是23)。
sudo iptables -A INPUT -p tcp --dport 23 -j DROP
為了使規則永久生效,你需要保存iptables規則。具體方法取決于你的Linux發行版。
ufw如果你使用的是Uncomplicated Firewall (ufw),可以這樣操作:
sudo ufw deny 23/tcp
sudo ufw reload
如果你確定不再需要Telnet服務,可以完全卸載它。
在Debian/Ubuntu上:
sudo apt-get remove --purge inetd xinetd telnetd
在CentOS/RHEL上:
sudo yum remove xinetd telnet
無論你使用哪種方法,最后都應該驗證Telnet服務是否已成功禁用。
sudo systemctl status telnet.socket # 如果使用systemctl
# 或者
sudo service xinetd status # 如果使用service
你應該看到Telnet服務處于停止狀態。
通過以上步驟,你應該能夠在Linux系統中成功禁用Telnet服務。