温馨提示×

centos minimal怎么开启ssh

小樊
45
2026-09-14 21:51:45
栏目: 智能运维

在 CentOS Minimal(最小化安装)中,默认通常没有开启 SSH 服务,需要手动安装并启动。步骤如下:


1. 安装 openssh-server

sudo yum install -y openssh-server

(CentOS 8 / Stream 可用 dnf)


2. 启动 SSH 服务

sudo systemctl start sshd

3. 设置开机自启

sudo systemctl enable sshd

4. 检查 SSH 状态

sudo systemctl status sshd

看到 active (running) 即表示已开启。


5. 防火墙放行(如果启用了 firewalld)

sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload

6. 查看 IP 地址(用于远程连接)

ip addr

然后用客户端连接:

ssh 用户名@服务器IP

常见问题

  • 连不上:确认 sshd 已启动、防火墙放行、网络互通
  • root 无法登录:编辑 /etc/ssh/sshd_config
    PermitRootLogin yes
    
    修改后重启:
    sudo systemctl restart sshd
    

如果你用的是 CentOS 7 / 8 / Stream 或是在 虚拟机 / 云服务器 环境,我可以给你更具体的命令。

0 踩