在CentOS系统中开启SFTP功能,通常需要通过配置SSH服务器来实现。以下是详细步骤:
安装OpenSSH服务器(如果尚未安装):
sudo yum install openssh-server
启动并启用SSH服务:
sudo systemctl start sshd
sudo systemctl enable sshd
检查SSH服务状态:
sudo systemctl status sshd
配置SSH以允许SFTP:
/etc/ssh/sshd_config:sudo vi /etc/ssh/sshd_config
#):Subsystem sftp /usr/libexec/openssh/sftp-server
yes:PasswordAuthentication yes
重启SSH服务:
sudo systemctl restart sshd
测试SFTP连接: 使用SFTP客户端连接到服务器,例如:
sftp username@hostname
如果你的CentOS系统启用了Firewalld,还需要配置防火墙以允许SFTP流量:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
如果SELinux处于 enforcing 模式,可能需要调整SELinux策略以允许SFTP:
检查SELinux状态:
sestatus
临时设置SELinux为 permissive 模式(仅用于测试):
sudo setenforce 0
测试SFTP连接。
永久设置SELinux为 permissive 模式(如果需要):
编辑 /etc/selinux/config 文件:
sudo vi /etc/selinux/config
将 SELINUX=enforcing 改为 SELINUX=permissive,然后重启系统。
通过以上步骤,你应该能够在CentOS系统上成功开启SFTP功能。