SSH(Secure Shell)是推荐的远程登录方式,提供加密通信。
# Ubuntu/Debian
sudo apt update
sudo apt install openssh-server
# CentOS/RHEL
sudo yum install openssh-server
# 启动服务
sudo systemctl start sshd
# 设置开机自启
sudo systemctl enable sshd
# 检查状态
sudo systemctl status sshd
编辑配置文件 /etc/ssh/sshd_config
:
sudo nano /etc/ssh/sshd_config
常见配置项:
- Port 22
(可修改为其他端口增强安全性)
- PermitRootLogin no
(禁止root直接登录)
- PasswordAuthentication yes/no
(是否允许密码登录)
- AllowUsers username
(指定允许登录的用户)
修改后重启服务:
sudo systemctl restart sshd
# 如果使用UFW (Ubuntu)
sudo ufw allow ssh
# 或指定端口
sudo ufw allow 2222/tcp
# 如果使用firewalld (CentOS/RHEL)
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
Telnet是不加密的协议,不建议在生产环境使用,仅建议在内网测试环境使用。
# Ubuntu/Debian
sudo apt install telnetd
# CentOS/RHEL
sudo yum install telnet-server
# Ubuntu/Debian (使用inetd/xinetd)
sudo systemctl start inetd
sudo systemctl enable inetd
# CentOS/RHEL
sudo systemctl start telnet.socket
sudo systemctl enable telnet.socket
# UFW
sudo ufw allow telnet
# firewalld
sudo firewall-cmd --permanent --add-service=telnet
sudo firewall-cmd --reload
ssh username@server_ip -p port_number
telnet server_ip
如需更详细的安全配置,建议参考Linux发行版的官方文档或安全最佳实践指南。