How to use Linux as file server

www.l‮a‬utturi.com
How to use Linux as file server

To use Linux as a file server, you will need to set up a network file system (NFS) or a common internet file system (CIFS) share.

Setting up an NFS share

1. Install the NFS server package. On most Linux distributions, you can install the NFS server package by running the following command:
sudo apt install nfs-kernel-server
  1. Create a directory to share. Choose a directory on your Linux machine that you want to share with other devices on the network. For example, you might create a directory named /mnt/nfs-share.

  2. Edit the /etc/exports file. This file specifies the directories that are exported by the NFS server, and the options for each export. Add a line to the file for the directory you want to share, specifying the network addresses that are allowed to access the share.

For example, to share the /mnt/nfs-share directory with devices on the 192.168.1.0/24 network, you can add the following line to the /etc/exports file:

/mnt/nfs-share 192.168.1.0/24(rw,sync,no_subtree_check)
  1. Restart the NFS server. After you have edited the /etc/exports file, you will need to restart the NFS server for the changes to take effect. You can do this by running the following command:
sudo systemctl restart nfs-kernel-server
  1. Access the NFS share from other devices. On other devices on the network, you can mount the NFS share by using the mount command. For example, to mount the /mnt/nfs-share directory on the Linux file server at 192.168.1.100 to the /mnt/nfs directory on the local device, you can use the following command:
sudo mount 192.168.1.100:/mnt/nfs-share /mnt/nfs

Setting up a CIFS share

1. Install the CIFS utilities package. On most Linux distributions, you can install the CIFS utilities package by running the following command:
sudo apt install cifs-utils
  1. Create a directory to share. Choose a directory on your Linux machine that you want to share with other devices on the network. For example, you might create a directory named /mnt/cifs-share.

  2. Edit the /etc/samba/smb.conf file. This file specifies the shares that are exported by the CIFS server, and the options for each share. Add a section to the file for the directory you want to share, specifying the network addresses that are allowed to access the share, and the permissions for each user or group.

For example, to share the /mnt/cifs-share directory with devices on the 192.168.1.0/24 network, allowing read and write access for the sambausers group, you can add the following section to the /etc/samba/smb.conf file:

[cifs-share]
comment = Samba on Linux
path = /mnt/cifs-share
valid users = username
read only = No
browsable = yes
  1. Now that we have our new share configured, save it and restart Samba for it to take effect:
sudo service smbd restart
  1. Update the firewall rules to allow Samba traffic:
sudo ufw allow samba
  1. Since Samba doesn
Created Time:2017-10-29 22:08:40  Author:lautturi