> For the complete documentation index, see [llms.txt](https://linux.microcisco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linux.microcisco.com/linux-how-to-do/sysadmin/disk/directory-share-nfs-cifs.md).

# Directory Share - NFS,CIFS

Network File Share (NFS)  and Common Internet File Share (CIFS) are both use for directory sharing. One purely between UNIX/Linux systems (NFS) and the other between UNIX/Linux and Windows Systems (CI

## Network File System (NFS)

NFS was introduced by Sun Microsystems and is used between UNIX/Linux Systems for directory/file sharing and uses port&#x20;

## Configure and Install on Linux (Ubuntu 20.04)

### Server:&#x20;

#### Step 1: Install NFS software

Install the **`nfs-kernel-server`** package onto the server. We need to update the system packages before we install:

<mark style="color:orange;">**`sudo apt update`**</mark>

<mark style="color:orange;">**`sudo apt install nfs-kernel-server`**</mark>

#### **Step 2: Create a NFS Export Directory**

Create a directory that will be shared among all client members. This is also known as the <mark style="color:purple;">'</mark><mark style="color:purple;">**export directory**</mark><mark style="color:purple;">'</mark> To restrict access to these files we will add the respective users to the specific groups for that share.

<mark style="color:orange;">**`sudo mkdir -p /mnt/nfs-share`**</mark>

#### Step 3: Create Groups, Add Users To Groups and Change Permissions

* We will now create a group that the users will belong to to access the files within the shared NFS directory

  <mark style="color:orange;">**`sudo groupadd nfs_share`**</mark>
* To list all the groups we can use the **`cat /etc/group`** command
* We will now create a user and add that user to the group. We don't want the users to be able to login to the server using ssh (ie no shell) and having a home directory
* They must just be able to access the shared directory by their username and that username belonging to the nfs-share group.
* We normally user the command <mark style="color:purple;">**add**</mark>user \<user> command which will create a user and home directory,but if we use the **`sudo useradd -M james.smith --shell /bin/false`** command and we can create a user without a home directory and no shell

  <mark style="color:orange;">**`sudo useradd -M james.smith --shell /bin/false`**</mark>&#x20;

  <mark style="color:orange;">**`sudo passwd james.smith`**</mark>
* We want users to belong to the nfs\_share group, so we add them using the <mark style="color:purple;">**'usermod -aG'**</mark> command which ammends their username to the group G

  <mark style="color:orange;">**`sudo usermod -aG nfs_share james.smith`**</mark>
* We need to change the permissions on the "export directory" we created above:

  <mark style="color:orange;">**`sudo chown -R nobody:nfsshare /mnt/nfsshare`**</mark>

  <mark style="color:orange;">**`sudo chmod -R 770 /mnt/nfs_share`**</mark>

#### S
