SSH (Secure Shell) 服务是远程管理Linux系统的标准方式。以下是开启SSH服务的详细步骤:
首先检查系统是否已安装SSH服务以及当前状态:
# 对于大多数基于Debian/Ubuntu的系统
sudo systemctl status ssh
# 对于基于RHEL/CentOS的系统
sudo systemctl status sshd
sudo apt update
sudo apt install openssh-server
sudo yum install openssh-server
sudo dnf install openssh-server
# Ubuntu/Debian
sudo systemctl start ssh
# CentOS/RHEL
sudo systemctl start sshd
# Ubuntu/Debian
sudo systemctl enable ssh
# CentOS/RHEL
sudo systemctl enable sshd
# 检查服务状态
sudo systemctl status ssh # 或 sshd
# 检查SSH端口(22)是否监听
sudo netstat -tulnp | grep ssh
如果系统启用了防火墙,需要开放SSH端口(默认22):
sudo ufw allow ssh
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
从另一台机器测试连接:
ssh username@server_ip_address
配置文件通常位于 /etc/ssh/sshd_config
。修改后需要重启服务:
sudo nano /etc/ssh/sshd_config # 进行修改
sudo systemctl restart ssh # 或 sshd
常见配置选项:
- 修改默认端口:Port 2222
- 禁用root登录:PermitRootLogin no
- 限制用户访问:AllowUsers username1 username2
希望这些信息对您有所帮助!如需更详细的配置指导,请告诉我您的具体Linux发行版和需求。