Create a Shared Directory on Samba AD DC and Map to Windows_Linux Clients


In this tutorial, we will be setting up a shared directory on a Samba Active Directory Domain Controller (AD DC) and mapping it to Windows and Linux clients. This will allow users to access and share files between their computers easily and securely. Samba is an open-source software suite that provides file and print services on various operating systems, including Windows and Linux. Active Directory (AD) is a directory service developed by Microsoft, which is used to manage and authenticate network resources. Combining Samba and AD creates a powerful and flexible file-sharing solution for organizations of all sizes.

Prerequisites

Before we get started, make sure you have the following −

  • A Linux server with Samba and Active Directory installed and configured.

  • One or more Windows and Linux clients that are joined to the AD domain.

Creating a Shared Directory

To create a shared directory, we will need to create a directory on the Samba AD DC server and set the appropriate permissions. We will also need to configure Samba to share the directory with clients on the network.

Step 1: Create a directory

First, create a directory for the shared files. For example, we will create a directory called "shared" in the root directory −

sudo mkdir /shared

Step 2: Set permissions

Next, we need to set the appropriate permissions for the directory. We will create a new group called "sambausers" and add the necessary users to this group. Then we will set the group ownership of the shared directory to "sambausers" and give the group read-write-execute permissions.

sudo groupadd sambausers
sudo usermod -aG sambausers username1
sudo usermod -aG sambausers username2
sudo chown -R :sambausers /shared
sudo chmod -R 770 /shared

Replace "username1" and "username2" with the actual usernames of the users who need access to the shared directory.

Step 3: Configure Samba

Next, we need to configure Samba to share the "shared" directory with clients on the network. Open the Samba configuration file for editing −

sudo nano /etc/samba/smb.conf

Add the following lines at the end of the file −

[shared]
comment = Shared directory
path = /shared
read only = no
valid users = @sambausers

Save and close the file.

Step 4: Restart Samba

Restart the Samba service for the changes to take effect −

sudo systemctl restart smbd

Mapping the Shared Directory to Windows Clients

Now that we have set up the shared directory on the Samba AD DC server, we can map it to Windows clients.

Step 1: Open File Explorer

Open File Explorer on the Windows client.

Step 2: Map the network drive

Click on "Computer" in the left-hand navigation pane and select "Map network drive" from the ribbon menu.

Step 3: Specify the network location

In the "Map Network Drive" dialog box, specify the network location of the shared directory. For example, if the Samba AD DC server has the IP address 192.168.1.10, the network location would be −

\192.168.1.10\shared_directory

Replace "shared_directory" with the name of the directory you shared in Step 2.

Step 4: Specify credentials

Next, you need to specify the credentials to access the shared directory. Click on the "Connect using different credentials" checkbox and enter the username and password of a user account on the Samba AD DC server with permission to access the shared directory.

Step 5: Map the network drive

Click "Finish" to complete the process. You should now see the shared directory as a mapped network drive in Windows Explorer.

Mapping to Linux Clients

To map the shared directory to Linux clients, you can use the mount command. The mount command is used to mount file systems, including network file systems, in the Linux operating system.

Step 1: Install cifs-utils

First, you need to install the cifs-utils package, which provides support for mounting CIFS/SMB file systems in Linux −

sudo apt-get install cifs-utils

Step 2: Create a mount point

Next, create a directory to use as the mount point for the shared directory. For example −

sudo mkdir /mnt/shared_directory

Step 3: Mount the shared directory

Use the mount command to mount the shared directory −

sudo mount -t cifs //192.168.1.10/shared_directory /mnt/shared_directory -o user=username,password=password,domain=ad_domain

Replace "192.168.1.10" with the IP address of the Samba AD DC server, "shared_directory" with the name of the shared directory, "username" with the username of a user account on the Samba AD DC server with permission to access the shared directory, "password" with the password for the user account, and "ad_domain" with the name of the Active Directory domain.

Step 4: Verify the mount

Use the df command to verify that the shared directory is mounted −

df -h

You should see the shared directory listed as a mounted file system.

Conclusion

By following these steps, you can easily create a shared directory on a Samba AD DC server and map it to Windows and Linux clients. This can be a useful way to provide a centralized location for users to store and share files, and can help improve collaboration and productivity in your organization.

Updated on: 26-Jun-2023

733 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements