Now that I have a computer set up with a mdadm raid1 I need to get a Samba server running so I can access my files from other computers (including those running Windows).

Installing Samba

First we’ll want to install Samba (if it isn’t already installed):
sudo apt-get install samba
You’ll also want to install these utility packages which will make the Samba share easier to configure:
sudo apt-get install samba-common-bin
You should now be able to connect to the server on a windows pc by using:
\\[ip]

Create a Folder to Share

Now I’ll create a folder which will be our shared folder. I have chosen to create a test folder on the desktop:
mkdir ~/Desktop/SambaShare
You also will need to change the permissions of the file so that other (Samba) users can write files there. By default, when you create a directory (or file) only the creator will be given r/w permission.
chmod 777 ~/Desktop/SambaShare
We can also create a test file in it:
touch ~/Desktop/SambaShare/test.txt
If you don’t change the permissions a Samba user will not be able to edit the file:
chmod 777 ~/Desktop/SambaShare/test.txt
To look at the permissions you can use:
ls -all ~/Desktop/SambaShare

Configuring Samba

That was easy! Now we’ll need to configure Samba. Most of the configuration will be done in /etc/samba/smb.conf.
The first thing you might want to do however, is backup the original file:
cp /etc/samba/smb.conf /etc/samba/smb.conf.org
We can now create/edit the .conf file:
sudo nano /etc/samba/smb.conf
“Each section of the smb.conf file that specifies a share, or a meta-service, is called a stanza. The global stanza specifies settings that affect all the other stanzas in the smb.conf file. Configuration parameters are documented in the smb.conf man page. Some parameters can be used only in the global stanza, some only in share or meta-service stanzas, and some can be used globally or just within a share or meta-service stanza.”
Workgroup:
You’ll want to make sure that the workgroup is correct:
[global]
workgroup = WORKGROUP
Creating a Share:
Add these lines to the end to create a share definition:
#This is the name of the share
[SambaShare] 
comment = Test Share
#specifies the directory to be shared
path = /home/[username]/Desktop/SambaShare

#enables Windows clients to browse the shared directory using Windows Explorer 
browsable = yes
#allows clients to connect to the share without supplying a password.
guestok = yes
#determines if the share is read only or if write privileges are granted. Write privileges are allowed only when the value is no
read only = no
#created files will be readable by others, but only writeable by the user
create mask = 0755
After you safe the file you can check it for syntax errors using:
sudo testparm
To make the changes become effective we need to restart Samba:
sudo restart smbd
You should now see a shared folder called ‘SambaShare’ from your Windows computer.

Security and Samba Users

Now whilst this is working all well and good, there is a small security concern in than any computer can modify the files. To fix this flaw we will create a Samba user which will be used to access the Share.
It’s important to realise about Samba is that it stores its own set of user accounts, separate from the main accounts, in the /etc/samba/smbpasswd file. That means you’ll need to create a separate Samba user for every user you want to access your file shares. You create a user using the smbpasswd command:
sudo smbpasswd -a felix
Now that we have a Samba user we can customise the share. The below share definition allows guests to connect but gives them read only permissions. But, a write list has been created (with our newly created user) so that if that user connects they will have write permissions:
#This is the name of the share
[SambaShare] 
comment = Test Share
#specifies the directory to be shared
path = /home/[username]/Desktop/SambaShare

#enables Windows clients to browse the shared directory using Windows Explorer 
browsable = yes
#allows clients to connect to the share without supplying a password.
guestok = yes
#determines if the share is read only or if write privileges are granted. Write privileges are allowed only when the value is no
read only = yes
 
#created files will be readable by others, but only writeable by the user
create mask = 0755
 
#a list of users who will have wrote permission
write list = felix
 
Now, when user connects from a windows machine they will connect by default as a guest which means they will have read-only permissions:
However, you can ‘map a network connection’ and check the box that you want to ‘connect using different credentials’. You can then provide the details of the user you have on the ‘write list’ to get writeable access (as long as they are an existing Samba user):

Connecting to the Samba share from Linux:

You can also connect to the Samba share from Linux by selecting File -> Connect to Server. You then need to enter the IP of the server allong with the share name and credentials:

Reading:

Advertisements