Mounting SFTP and FTP shares

From Gentoo Linux Wiki
Jump to: navigation, search

Filesystems TOC

Filesystem.png


This article deals with Filesystem in USErspace (FUSE) and (CurlFtpFS). The first enables the user to mount all kinds of filesystems (including SSH and FTP) at a local mountpoint. CurlFtpFS is a filesystem for acessing FTP hosts based on FUSE and libcurl.

Contents

[edit] Installing and using FUSE

Make sure you have Filesystem in Userspace support enabled in your kernel:

Linux Kernel Configuration: I was using 2.6.26-gentoo-r3
    File systems  --->
        <M> Filesystem in Userspace support

Both, sshfs and CurlFTPFS, have FUSE as dependency. It is easy in installation. Simply:

emerge sys-fs/fuse

Then:

modprobe fuse

and make sure fuse is in modules.autoload:

echo fuse >> /etc/modules.autoload.d/kernel-2.6

[edit] Mounting SFTP shares

emerge sys-fs/sshfs-fuse

To mount a remote host's file system through SSH at a local mount point, all you have to do is type:

sshfs [user@]host:[dir] mountpoint

To allow access to mountpoint for non-root users simply execute:

sshfs [user@]host:[dir] mountpoint -o allow_other

To unmount a remote host's file system type:

fusermount -u mountpoint

[edit] Mount and Unmounting FTP shares

Installing CurlFtpFS:

emerge -av net-fs/curlftpfs

CurlFtpFS uses typical FTP syntax:

curlftpfs ftp://ftp.gentoo.org/ /path/to/mountpoint

To unmount an ftp host:

fusermount -u /path/to/mountpoint/

A better way is use mount and umount. To do this the following lines need to be added to /etc/fstab:

File: /etc/fstab
curlftpfs#user:password@server.tld/remote/path /mount/point fuse user,disable_eprt,noauto
curlftpfs#user:password@server.tld/remote/path /mount/point fuse.curlftpfs user,disable_eprt,noauto

The first line allows mount to work, the second umount to work. Additional options are:

User and password : ftp://user:password@ftp.gentoo.org/

Specific port : ftp://ftp.gentoo.org:8585


Now, you should be able to:

mount /path/to/mountpoint

and

umount /path/to/mountpoint

[edit] Automounting

Automounting is an even better method. The following is a setup for automounting removable media on an Xterminal. On the terminal

File: /etc/autofs/auto.master
/home/ftp/auto	/etc/autofs/auto.misc	--timeout=1	--ghost
File: /etc/autofs/auto.misc
cdrom		-fstype=iso9660,ro	:/dev/sr0
floppy		-fstype=auto		:/dev/fd0
usb-storage	-fstype=auto,umask=000		:/dev/sda1

So, it sets up the automounts in FTP's home. Establish FTP and test the automounting by FTPing to the Xterminal's FTP server.

On the application server

File: /etc/autofs/auto.master
/mnt/removables	/etc/autofs/auto.misc	--timeout=2	--ghost
File: /etc/autofs/auto.misc
usb-storage	-fstype=curl,allow_other	:ftp\://anonymous\:PASSWORD\@mr-muddle/usb-storage
floppy	 -fstype=curl,allow_other	:ftp\://anonymous\:PASSWORD\@mr-muddle/floppy
cdrom	 -fstype=curl,allow_other	:ftp\://anonymous\:PASSWORD\@mr-muddle/cdrom
images	 -fstype=curl,proxy=http\://192.168.1.1\:3128	 :ftp.vwx.yz/images

Automount won't understand fstype=curl without the following files:

File: /sbin/mount.curl
#! /bin/sh
curlftpfs $1 $2 -o allow_other,disable_eprt $3
chmod 755 /sbin/mount.curl
File: /sbin/umount.curl
#! /bin/sh
fusermount -u $1
chmod 755 /sbin/umount.curl
Personal tools