Objective
Create a private and public SMB share. The private share should use your first name and a password. The public share should be viewable/writable to everyone. Use yourname_private and yourname_public for the share names.
Install Samba Server
Logon to the Ubuntu machine to install Samba. To install Samba, run the commands below.
sudo apt-get install samba samba-common python-glade2 system-config-samba |
Configure Samba Public share
Now that Samba is installed, run the commands below to backup its default configuration file.
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak |
Next, create the directory where you want to store your files and change the permissions. I am using the -p option to create the parent folder if it doesn’t exist. The -R option means Recursive, and is not required if the folder is empty. Commands are case sensitive.
sudo mkdir -p /shares/mark_public sudo chown -R nobody:nogroup /shares/mark_public sudo chmod -R 775 /shares/mark_public |
Next, open Samba configuration file by running the commands below.
We will be using Nano for this operation, but you can also use vi.
sudo nano /etc/samba/smb.conf |
Copy and paste the content below into the file and save… this will create a share named Public where everyone will have access on the Ubuntu to it…
#============================ Global definition ================================ [global] workgroup = WORKGROUP server string = Mark Server %v netbios name = mark-file-server security = user map to guest = bad user name resolve order = bcast host dns proxy = no bind interfaces only = yes #============================ Share Definitions ============================== [Mark Public] <span style="color: #ff0000;">path = /shares/mark_public</span> writable = yes guest ok = yes guest only = yes read only = no create mode = 0777 directory mode = 0777 force user = nobody |
Save your changes with Ctrl+X, Y, Enter.
Restart Samba using the command below to load your new configuration.
sudo service smbd restart |
Configure Samba Private Share
Now you know how to create Samba public shares, let’s go and create private and protected shares. Only users that are member of the approved group will be able to access the secure location with passwords.
First create a samba group called smbgroup for the share.. only members will have access. To create a groups in Ubuntu, run the commands below.
sudo addgroup smb |
Then add a user to the group by running the commands below
sudo usermod -aG smb mark |
Finally, all users who need to access a protected samba share will need to type a password. To add a user to samba password database, run the commands below for each user.
sudo smbpasswd -a mark |
The user will be prompted to enter and confirm a password. This password will be used to access the protected samba shares.
Next, go and create a protected share in the /shares directory.
sudo mkdir -p /shares/mark_private |
Then give only root and members group access to this share.
sudo chown -R root:mark /shares/mark_private sudo chmod -R 0770 /shares/mark_private |
When you’re done creating the protected share, go and share it in the smb.conf file.
sudo nano /etc/samba/smb.conf |
Then append the configuration block below into the smb.conf file.
[Mark Private] path = /shares/mark_private valid users = @smb guest ok = no writable = yes browsable = yes |
Save your changes with Ctrl+X, Y, Enter.
Restart Samba using the command below to load your new configuration.
sudo service smbd restart |
If you’re on Windows, you should be able to see your shares now.