温馨提示×

centos挂载FTP服务器的步骤

小樊
51
2025-09-20 04:59:33
栏目: 云计算

一、准备工作

  1. 更新系统软件包:sudo yum update -y
  2. 安装curlftpfs工具(用于挂载FTP):
    • 若系统未启用EPEL仓库,先执行:sudo yum install epel-release -y
    • 再安装curlftpfs:sudo yum install curlftpfs -y

二、创建本地挂载点 选择一个空目录作为FTP服务器的挂载目录(如/mnt/ftp~/ftp_mount):
sudo mkdir -p /mnt/ftp
(注:-p参数可自动创建父目录,若目录已存在则无需重复创建)

三、挂载FTP服务器

  1. 基本挂载(命令行明文输入密码)
    执行以下命令,替换ftp.example.com(FTP服务器地址)、your_username(FTP用户名)、your_password(FTP密码):
    sudo curlftpfs ftp.example.com /mnt/ftp -o user=your_username:your_password
  2. 安全挂载(使用.netrc文件存储凭据)
    • 创建或编辑~/.netrc文件:nano ~/.netrc
    • 添加以下内容(替换对应信息):
      machine ftp.example.com
      login your_username
      password your_password
      
    • 保存退出后,执行挂载命令(无需指定用户名密码):
      sudo curlftpfs ftp.example.com /mnt/ftp

四、验证挂载结果 执行df -h命令,查看输出中是否有类似以下行(表示挂载成功):
fuse.curlftpfs ftp.example.com 20G 15G 4.0G 78% /mnt/ftp

五、(可选)设置开机自动挂载

  1. 编辑/etc/fstab文件:sudo vi /etc/fstab
  2. 在文件末尾添加以下内容(替换对应信息,_netdev参数表示网络设备,需等待网络就绪):
    ftp.example.com /mnt/ftp fuse.curlftpfs _netdev,user,allow_other,default_permissions 0 0
    
  3. 测试配置是否正确:sudo mount -a(无错误提示则表示配置成功)

六、卸载FTP服务器 当不再需要挂载时,执行以下命令:
sudo umount /mnt/ftp
或使用fusermount(部分系统可能需要):
fusermount -u /mnt/ftp

注意事项

  • 确保FTP服务器允许你的IP地址访问,且用户名/密码正确;
  • 若FTP服务器使用SSL/TLS加密,需添加-o protocol=ssl选项(如:sudo curlftpfs ftp.example.com /mnt/ftp -o user=your_username:your_password -o protocol=ssl);
  • 生产环境中,避免在/etc/fstab中明文存储密码,建议使用passwd_file选项(如:password_file=/etc/curlftpfs-passwd,并将凭据文件权限设为600)。

0