在 CentOS 上“挂载 SFTP 目录”,通常有两种常见理解,我分别说明:
sshfs(最常用、最简单)yum install -y epel-release
yum install -y sshfs
mkdir -p /mnt/sftp
sshfs user@remote_host:/remote/path /mnt/sftp
示例:
sshfs test@192.168.1.100:/home/test /mnt/sftp
编辑 /etc/fstab:
user@remote_host:/remote/path /mnt/sftp fuse.sshfs defaults,_netdev 0 0
⚠️ 需要配置 SSH 免密登录,否则开机无法自动挂载
curlftpfs(不推荐 SFTP,仅 FTP)SFTP 不支持,忽略。
如果你是服务端,让别人来挂载:
systemctl status sshd
useradd sftpuser
passwd sftpuser
编辑 /etc/ssh/sshd_config:
Match User sftpuser
ChrootDirectory /data/sftp
ForceCommand internal-sftp
X11Forwarding no
重启 SSH:
systemctl restart sshd
firewall-cmd --add-service=ssh --permanent
firewall-cmd --reload
如果你能说明:
我可以给你更精确的命令。