Most common ways to share files from a Linux server are using the following services:
- FTP
- NFS
- Samba
- HTTP
- SFTP
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:
vsftpd
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:
write_enable=YES
Enable local users to login (those defined in /etc/passwd)
local_enable=YES
To prevent users from leaving their home directories enable chroot:
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
chroot_local_user=YES
Limiting users:
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO
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
[General]
Verbosity=0
Pipefs-Directory=/var/lib/nfs/rpc_pipefs
Domain=localdomain
[Mapping]
Nobody-User=nobody
Nobody-Group=nobody
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 172.16.41.138
Export list for 172.16.41.138:
/home/ovi 192.168.1.0/24
And mount it:
# mount -t nfs 172.16.41.138:/home/ovi /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:
[dir]
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:
\\server_IP\dir
dir - is the name of my share.
4. HTTP
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 0.0.0.0 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.
5. SFTP
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@172.16.41.138
Password:
Connected to 172.16.41.138.