Simple file sharing options in Linux

Most common ways to share files from a Linux server are using the following services:
- Samba

In this example I am using a SLES 11 SP3.

1. FTP

SLES comes preinstalled with lukemftp, but I will use vsftpd:

zypper> in vsftpd
Resolving package dependencies...

The following NEW package is going to be installed:
1 new package to install.
Overall download size: 128.0 KiB. After the operation, additional 292.0 KiB will be used.
Continue? [y/n/?] (y): 
Retrieving package vsftpd-2.0.7-4.25.1.i586 (1/1), 128.0 KiB (292.0 KiB unpacked)
Installing: vsftpd-2.0.7-4.25.1 [done]
linux-97fc:~ # /etc/init.d/vsftpd start
Starting vsftpd                                             done
linux-97fc:~ # 

By default the ftp server is configured to allow login for the anonymous user, and no password.
This behaviour can be changed in /etc/vsftpd.conf

Enable uploading:


Enable local users to login (those defined in /etc/passwd)


To prevent users from leaving their home directories enable chroot:


Limiting users:


The file /etc/vsftpd.user_list must contain the users allowed to login.

2. NFS

Main file is located at /etc/exports which contains a list of exported filesystems.
Edit the file manually to add directories to the export list. A sample file looks like this:

# /etc/exports - exports(5) - directories exported to NFS clients
# Example for NFSv2 and NFSv3:
#  /srv/home        hostname1(rw,sync) hostname2(ro,sync)
# Example for NFSv4:
#  /srv/nfs4        hostname1(rw,sync,fsid=0)
#  /srv/nfs4/home   hostname1(rw,sync,nohide)
# Using Kerberos and integrity checking:
#  /srv/nfs4        *(rw,sync,sec=krb5i,fsid=0)
#  /srv/nfs4/home   *(rw,sync,sec=krb5i,nohide)
# Use `exportfs -arv` to reload.

ID mapping
Edit /etc/idmap.conf and add the domain





After editing the exports file start the nfs server:

linux-97fc:~ # /etc/init.d/nfsserver start
Starting kernel based NFS server: idmapd mountd statd nfsd sm-notify                                                                                                            done
linux-97fc:~ #

On my client I can check for the exported directory:

$ showmount -e
Export list for

And mount it:

# mount -t nfs /mnt

3. Samba

Samba allows you to share files from linux to a windows client. It is installed by default in SLES 11 so I just need to start it:

linux-97fc:~ # /etc/init.d/smb start

and run testparm to check the validity of the configuration file.

Creating shares:

/etc/samba/smb.conf contains a list of shares already defined, like users, homes, printers etc.
To share a specific directory add it like this:

    path = /home/ovi
    create mask = 0700
    read only = no

Adding a user:

# useradd samba_user

Create a samba user account:

# pdbedit -a -u samba_user

To change samba user’s pw:

# smbpasswd samba_user

Restart smb

# /etc/init.d/smb restart

In a windows client I can now access /home/ovi at this address:


dir - is the name of my share.


There are many open source web servers out there, but one of the simplest way to share files using http is with python.
Simply type:

linux-97fc:~ # python -m SimpleHTTPServer 34
Serving HTTP on port 34 ...

where 34 is a random port I chose.
Obviously this offers no security and it’s just for fast file sharing.

Python 3.x uses a different module name, so use:
# python -m http.server

NOTE: To choose which directory to share, make sure you issue the command inside that directory.


SFTP refers to a few secure methods of sharing files. I will use the ssh file transfer protocol.
SSH needs to be installed and configured.
Open this file /etc/ssh/sshd_config and add this line or uncomment:

Subsystem       sftp    /usr/lib/ssh/sftp-server

Access via sftp should now work.

# sftp ovi@
Connected to