在 CentOS 系统中,查看 SSH 端口(默认是 22)有几种常见方法,下面按推荐顺序给你说明:
SSH 的端口是在配置文件中定义的:
cat /etc/ssh/sshd_config | grep -i port
或者更清晰一点:
grep ^Port /etc/ssh/sshd_config
输出示例:
Port 22
如果
Port前面有#,说明使用的是默认端口 22。
ss(推荐)ss -tlnp | grep sshd
示例输出:
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1234,fd=3))
说明:
22 就是当前 SSH 端口netstat(老系统)netstat -tlnp | grep sshd
firewall-cmd --list-ports
或:
firewall-cmd --list-all
iptables -L -n
semanage port -l | grep ssh
输出示例:
ssh_port_t tcp 22
ss -tlnp | grep sshd
22/etc/ssh/sshd_configsystemctl restart sshd
如果你愿意,可以告诉我:
我可以按你的实际情况给你更精确的操作步骤 ✅