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.
sudo apt install nfs-kernel-server
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
.
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)
/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
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
sudo apt install cifs-utils
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
.
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
sudo service smbd restart
sudo ufw allow samba