CentOS 装完默认就开了 sshd,用 root 加安装时设的密码理论上就能连,但生产环境更规范的做法是建专用运维账号、控制认证方式。这里给出账号创建到登录放行的完整链条。

创建可用 SSH 账号

  • 建用户:useradd -m ops,设密码 passwd ops。
  • 确认 shell:默认 /bin/bash 可登录;系统账号用 nologin 的不能用于 SSH。
  • sudo 授权:usermod -aG wheel ops(wheel 组默认有 sudo 权限)。

登录相关配置

  • sshd_config 里确认 PasswordAuthentication yes(密码登录)、PermitRootLogin 按需设置。
  • 防火墙:firewall-cmd --permanent --add-service=ssh && firewall-cmd --reload,改过端口就 add-port=2222/tcp。
  • SELinux 特殊场景:改过 SSH 端口要 semanage port -a -t ssh_port_t -p tcp 2222,否则 sshd 起不来。
  • 登录验证:ssh ops@服务器IP,密码不回显是正常行为,直接输完回车。

免密升级

客户端 ssh-keygen 生成密钥,公钥追加到服务器 ~ops/.ssh/authorized_keys,之后可关掉密码认证。建议:root 密码登录尽早关闭,wheel 组账号加 fail2ban,是 CentOS 服务器最经济的两个加固动作。