Sunday, March 15, 2009

Configure Linux file sharing with Samba

Windows file sharing uses a protocol called smb. Since Windows is the most commonly used operating system in the world, other operating systems offer compatibility with this protocol. This is done with a program called Samba. Today I set up Samba powered file sharing on my Ubuntu server. First, install the package:
sudo apt-get install samba
Configuration is done primarily through the Samba config file located at /etc/samba/smb.conf . Edit the line that says "workgroup = WORKGROUP" so that the all caps workgroup is the one you are using. Next, you need to add the following lines for each shared directory:

[share name]
comment = Shared Files
path = /path/to/share
writable = yes
browseable = yes
guest ok = no

What appears in brackets is the name your shared directory will have on the network, so name it something that makes sense. Make the comment say whatever you want. If you want the directory to be read only, switch the "writable" value to no. If you want to create a dropbox that will accept files but not allow others to read them, switch the "browseable" value to no. If you want to allow anonymous access, switch the "guest ok" value to yes. You may need to edit your file permissions to get this to work right. Do this using the chmod command.

You also need to setup which users may access your shared directories with the smbpasswd command:
sudo smbpasswd -a [username]
The username specified must be a legal user of the server. You will be prompted to enter a password. To make your changes take effect, restart the server:
sudo /etc/init.d/samba restart
If you need to tweak your config file you can tell the Samba daemon to reload the config file:
sudo /etc/init.d/samba reload

No comments:

Post a Comment