Setting up Samba Shares with Restricted and Public Access
Samba is a popular file sharing service for Linux and Unix systems that allows for easy access to files across a network. In this article, we will cover how to set up Samba shares with both restricted and public access. This is useful in situations where you want to allow anyone to access a certain share, such as a public pool, but also want to restrict access to other shares, such as sensitive documents.
Prerequisites
Before we begin, you will need to have Samba installed on your system. You can do this by running the following command:
sudo apt-get install samba
You will also need to have a basic understanding of how to navigate the file system and create and edit files using a text editor such as nano or vim.
Setting up a Public Share
To set up a public share, we first need to create a directory that will be shared. For this example, we will create a directory called /mypool/shared and give it the necessary permissions:
sudo mkdir /mypool/shared
sudo chmod 777 /mypool/shared
Next, we need to create a Samba configuration file for this share. We will call it shared.conf and place it in the /etc/samba/ directory:
sudo nano /etc/samba/shared.conf
In this file, we will add the following configuration:
[shared]
path = /mypool/shared
writeable = yes
create mask = 0777
directory mask = 0777
public = yes
This configuration sets up a share called shared with the path of /mypool/shared. It is set to be writeable, so that users can add, delete, and modify files in the share. The create mask and directory mask settings ensure that all files and directories created in the share have the necessary permissions. Finally, the public setting is set to yes, which allows anyone to access the share without requiring a username or password.
To make this share available to the network, we need to restart the Samba service:
sudo service smbd restart
Setting up a Restricted Share
To set up a restricted share, we will follow a similar process as the public share. However, instead of setting the public setting to yes, we will set it to no and specify a list of valid users.
First, we will create a directory for the restricted share:
sudo mkdir /mypool/restricted
sudo chmod 755 /mypool/restricted
Next, we will create a Samba configuration file for this share:
sudo nano /etc/samba/restricted.conf
In this file, we will add the following configuration:
[restricted]
path = /mypool/restricted
writeable = yes
create mask = 0755
directory mask = 0755
public = no
valid users = user1, user2
This configuration sets up a share called restricted with the path of /mypool/restricted. It is set to be writeable, but the create mask and directory mask settings are more restrictive than the public share. The public setting is set to no, which means that users will need to provide a username and password to access the share. The valid users setting specifies a list of users who are allowed to access the share.
To make this share available to the network, we need to restart the Samba service:
sudo service smbd restart
In this article, we have covered how to set up Samba shares with both restricted and public access. This is useful in situations where you want to allow anyone to access a certain share, such as a public pool, but also want to restrict access to other shares, such as sensitive documents. By following the steps outlined in this article, you will be able to create and configure Samba shares with the necessary permissions and access controls.