在 CentOS 上查看 SFTP 状态,通常 SFTP 是由 SSH 服务(sshd) 提供的,因此查看方式主要围绕 SSH 服务 和 端口监听 来判断。
下面按常见场景说明。
CentOS 7 / 8 / Stream(systemd):
systemctl status sshd
✅ 正常状态示例:
Active: active (running)
如果未启动:
systemctl start sshd
systemctl enable sshd
SFTP 默认使用 22 端口,查看监听状态:
ss -lntp | grep 22
# 或
netstat -lntp | grep 22
看到类似:
LISTEN 0 128 0.0.0.0:22
说明 SSH/SFTP 正在监听。
SFTP 依赖 sftp-server,检查配置:
grep -R sftp /etc/ssh/sshd_config
常见正常配置:
Subsystem sftp /usr/libexec/openssh/sftp-server
或(较新系统):
Subsystem sftp internal-sftp
如果这一行被注释或不存在,SFTP 将无法使用。
修改后需重启:
systemctl restart sshd
sftp localhost
成功示例:
sftp>
sftp user@服务器IP
查看当前 SSH/SFTP 登录用户:
who
或
ss -tnp | grep ssh
CentOS 默认日志位置:
/var/log/secure
查看 SFTP 登录记录:
tail -f /var/log/secure
或搜索:
grep sftp /var/log/secure
firewall-cmd --list-ports
setenforce 0
systemctl status sshd # 服务是否运行
ss -lntp | grep 22 # 端口是否监听
sftp localhost # 是否可用
如果你能告诉我:
我可以给你更精确的排查方案。