Friday, December 28, 2012

Installing Samba and sharing files within a home or office network


There are innumerable tutorials to explain sharing a folder, a partition or a disk drive using samba. Here's one more, it doesn't hurt, on the contrary it may help someone.

The best way to use old laptops and desktops is by installing a Linux distro and experimenting with it as a file server. After you install the OS and later ssh, samba, remote desktop, apache etc., you can add it to the network and do all the rest with another computer through remote desktop or ssh.

I used Linux Mint 14, Nadia, which is superb, in terms of quality, functionality, ease and aesthetics. In my scenario, I have mounted the storage partition as /D in my Linux Mint box. For this tutorial, we are going to use an ordinary user named "john" who's password will be needed to login to the samba network.

I am going to tell you how to install samba and share your folder step by step:

1) Install samba

sudo apt-get install samba


2) Stop samba in case it is running

sudo /etc/init.d/samba stop


3) Backup your default samba config file smb.conf (this step is optional)

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.backup


4) Under home or any location create a new smb.conf using, vi, nano, emacs, gedit, or kate

the contents looks like this:


[test]
path = /D
available = yes
valid users = john
read only = no
browsable = yes
public = yes
writable = yes

Explanation:

i) What does [test] mean ? Your shared folder will be called test in the network, but you can use any name as you like

ii) What is /D? It is the path is the path to the folder you want to share e.g if you want to share a newdirectory in home, it would be /home/john/newdirectory
In my case, I mounted the NTFS D partition (of windows) as /D so I used it.

iii) Who is john? john is a user whose credentials will be needed to login to the shared folder. john can be replaced by any name you want to use.

Save the smb.conf file.

5) Copy your created smb.conf to its right workplace

sudo cp smb.conf /etc/samba

6) Change permissions of the shared folder in case it does not have read-write permission to all users
sudo chmod 0777 /D

7) Add a user with access rights to the samba share

Create user john without a home (i.e., /home/john) using /bin/true feature

sudo useradd -s /bin/true john

Create password for john (optional), if you don't want to use john as normal user login, you can skip this step

sudo passwd john

8) Make sure you add john to group plugdev

sudo usermod -a -G plugdev john

9) Create a samba password same as above (same as login password) to avoid confusion

sudo smbpasswd -a john

9) Test the parameters

sudo testparm

10) Restart samba

sudo restart smbd

VoilĂ  samba

Check your folder in your Linux (under network) or windows network (under Workgroup). Enter username john and password, now your old computer is a silent new file server.

To stop sharing and removing samba:

1) Stop samba

sudo stop smbd


2) Delete user

sudo userdel -r john


3)

sudo apt-get remove samba --purge


PS: I personally feel running a computer as a server continuously for trivial functions is a huge waste of power. So shut down your "server" whenever you won't use it for extended periods of time. Everytime you start the computer, samba will come alive and serve your folders and files.