Wednesday, December 16, 2009

Share Folder on Ubuntu

Hi, I like google, so i wanna share things i got from google. It teach me a lots. But actually, our proposal still not completely done yet. We need to find more about the tools used, MySQL cluster stuff etc.
Now, let's see how to share directory in ubuntu and other Linux distributions.

It is very useful to share things over network. Computer users usually share their directories inside their LAN, containing files such as documents, audio files, or movies. This post will simply make your directory shared over network to Linux and Windows client. The famous Linux program used is samba (ask google please). I'm currently using Karmic Koala (9.10) so the default setting might be somewhat different from other versions.

Samba Server
There are two ways, graphical and command line interface. We will focus on CLI.

Step 1: install samba
$ sudo apt-get install samba

Step 2: configure samba file /etc/samba/smb.conf
Make sure backup the original file
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf

Then use any editor such as gedit, nano, etc.
$ sudo gedit /etc/samba/smb.conf

First, check these following lines are correctly in default
workgroup = WORKGROUP
server string = %h server (Samba, Ubuntu)

Note: the %h will show your hostname. So, put anything you want as the server name.

If you want to share your home directory, remove the semicolon on each of this line
; comment = Home Directories
; browseable = no

You also can share any directory you want by creating your own entry, but make sure the directory exists. For example, you might want to share your 'video' directory on path /home/user1/video, so you need to add these lines
comment = video
path = /home/user1/video
read only = yes
guest ok = yes
browseable = yes

Some explanations on this entry.
The bracket [..] is used to rename the shared directory
comment is just some note
path is the location of the share directory
read only, to disallow from being written
guest ok, allow 'guest' user to be connected without password

For example, Linux client can be connected by smbclient command with -U option which indicate as user. (will be explained in Linux and Windows Client section)
browseable, allow other users in network to see your shared directory
Some Tips:
Run this command inside share directory to make all directories, sub-directories and files are in read-only permission

For directory, (drwxr-xr-x)
$ find . -type d -exec chmod 755 {} \;

For files, (-rwr—r--)
$ find . -type d -exec chmod 644 {} \;

Linux client
For Linux client to connect to the shared directory, just go to nautilus and simply use the IP address or the hostname. Then you will see the shared directory.

Make sure you have installed smbclient package.
$ sudo apt-get install smbclient

Then, type the samba server IP address on nautilus location bar as follow:

Also can be opened from web browser, but the appearance will be same like ftp

Client also can connect thorugh command line.
To list files shared directory as user 'guest'. The user should be exist
$ smbclient -L // -U guest

Direcly connect (almost similar to ftp)
$ smbclient //server/shared_directory -U user

$ smbclient // shared_directory -U guest
Enter guest's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.4.0]
smb: \>

For Windows client
Start -> Run
Then type the IP address or hostname, also can be connected through windows explorer (same as nautilus).
It also can be opened from browser by entering server ip address

Hope this will help you. Enjoy!