It’s very useful to be able to view/edit files on your server out of a command-line environment, and the chances are that you have a Windows machine somewhere which you may use on a more daily bases, the difference in operating systems doesn’t have to act as a barrier between everything though, the 2 (or more) computers can easily communicate in perfect harmony with the use of Samba, a free, open source implementation of windows file sharing. When installed and configured correctly you can work on files that are stored on your server as if they were stored locally, all of your digital photo’s can be stored in one place for everyone to access, all your music in one place so you don’t have multiple copy’s on multiple computers, there’s just loads of advantages.
First of all you will need to install the samba server:
sudo apt-get install samba
Just follow the install process until you get back to the normal terminal.
Theoretically, it is now setup and fully configured, but the chances of it working straight away (and how you want it to) are very limited. All the settings are stored in /etc/samba/smb.conf, if you take a look inside that file you will see it seems a bit confusing! So the first thing we will do is get rid of that, so that we can start again.
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
That will copy the current config file so that it has the “.bak” extension, which means that it won’t be read when samba is trying to start, and is there just in case everything goes wrong! To create a blank configuration file it is easiest to just delete what is there, and create a new, empty file, execute the following:
sudo rm /etc/samba/smb.conf
sudo touch /etc/samba/smb.conf
That will remove the file (rm command) and then recreate it (touch command). You now need to create your new configuration file, here is an example of what it will look like:
[global]
workgroup = YourWorkgroupName
security = share
#Example Shared Folder
[SharedFolderName]
comment = A Comment
path = /path/to/the/folder/
public = yes
writeable = yes
create mask = 0777
That is just a very simple setup, and here is an explanation of what everything does:
workgroup = YourWorkgroupName - This is the name of your workgroup, commonly Home, or MSHome.
security = share - This tells samba to allow anyone connected to the network access to the shared folders, as apposed to requiring password verification.
[SharedFolderName] - Inside the square brackets is the name of the shared folder as you want it to appear when browsing for it, e.g. [Shared Documents] would create a shared folder called Shared Documents.
comment = A Comment - Quite simply a comment about the shared folder.
path = /path/to/the/folder/ - Just the local path to the folder.
public = yes - Allows everyone on the network access to it.
writeable = yes - Allows new files to be created, and current files to be modified.
create mask = 0777 - The permissions of new files created (0777 means read/write/modify/execute by everybody).
Here is an example file which I use to allow me to modify all documents in the root of the webs server, example Samba Config. You just need to insert the contents of that into the current smb.conf file, using:
sudo nano /etc/samba/smb.conf
Once you have finished editing the configuration, you will need to restart samba for changes to take effect, by doing:
sudo /etc/init.d/samba force-reload
Everything should restart by itself, if not check your config & post a comment for any help.
Please note that samba takes into account Ubuntu’s file permissions, so /var/www/ may, by default, only have write access for root, so to allow everyone (i.e. samba clients) to write files there do:
sudo chmod 777 /path/you/want/to/allow/access/to -R
Just remember the -R at the end, as that will apply the changes to all sub-folders and files as-well.