Saturday, June 13, 2015

Install And Configure Samba Server For File Sharing

Install And Configure Samba Server For File Sharing - File sharing is very important things you should learn. At a certain moment, we definitely need to share files, because everyone doesn't always bring USB flash drive or another media to copy their data. Samba can solve this situation. So I write how to share file on Linux using samba.

Samba is Free Software licensed under the GNU General Public License, the Samba project is a member of the Software Freedom Conservancy. Since 1992, Samba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol, such as all versions of DOS and Windows, OS/2, Linux and many others.

It is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environments. It can function both as a domain controller or as a regular domain member. And Samba is freely available, allows for interoperability between Linux/Unix servers and Windows-based clients.

Install Samba on Linux

In this second point, I write how to create a network share via Samba using the CLI (Command-line interface/Linux Terminal) in an uncomplicated, simple and brief way targeting Windows and Android users. To install samba, just open your terminal and hit the command below :

apt-get install samba

Next, create folder that we'll share, then change the permission. You can follow this commands :

mkdir linuxslaves-sharing
chmod 755 -R Desktop/linuxslaves-sharing/

Configure Samba Server For File Sharing

By using Samba, we have 2 options that we can use. There's :
  1. User Mode : Make shared folder only accessible for specific user / need login authentication.
  2. Guest-Mode : Make everyone get access shared folder / there's no login authentication.

I'll write both of them for you. As I said before, we targeting windows and android users. But in this case I used android to test this tutorial. Here's the step :

3.1 User Mode

I'll write for the first point "user mode" which make shared folder only accessible for specific user. So we must create / add new user and set smb password for that user. You can do it by follow this command :

# useradd linuxslaves
# smbpasswd -a linuxslaves
New SMB password:
Retype new SMB password:
Added user linuxslaves.

Ok, start to configure samba server. Open smb.conf which located in /etc/samba/smb.conf :

subl /etc/samba/smb.conf

Search code that say Share Definition code, then add this line code :

browseable = yes
path = /root/Desktop/linuxslaves-sharing/
writeable = yes
valid users = linuxslaves
admin users = root

Set the code that say read only = yes to read only = no. Seacrh # security = user code and remove '#'. So it would be like this :

#======================= Share Definitions =======================
#  comment = Home Directories
[homes]
#  comment = Home Directories
browseable = yes
path = /root/Desktop/linuxslaves-sharing/
writeable = yes
valid users = linuxslaves
admin users = root

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
read only = no
security = user

Explanation :
- path : Shared folder
- browseable : Permission for browse shared folder
- writeable : Permission for write shared folder
- valid users : Spesifics user we set before
- admin users : Administrator, by default you can write root


Save that configuration. Untill this step we already finish setup Samba. Please restart samba server and run by this command :

# /etc/init.d/samba restart 
[ ok ] Stopping Samba daemons: nmbd smbd.
[ ok ] Starting Samba daemons: nmbd smbd.
# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Global parameter security found in service section!
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

Now, Check at target machine. You'll see the the result :

File Sharing on Linux Using Samba

That screenshot take use my android phone. Happy sharing!

3.2 Guest Mode

Guest mode is actually not much different from first mode. This mode is easier than user mode, because we just give free access to all the client, so that anyone can access the folder / file that shared without perform login authentication (username and password). Open smb.conf and re-edit configuration code.

subl /etc/samba/smb.conf

Search security=user (we already remove '#' on user mode) then change with security = share. Edit share definition code. See the code below :

#======================= Share Definitions =======================
#  comment = Home Directories
browseable = yes
path = /root/Desktop/linuxslaves-sharing/
writeable = yes
guest ok = yes

Explanation :
- path : Shared folder
- browseable : Permission for browse shared folder
- writeable : Permission for write shared folder
- guest ok : Give access to all user guest (guest)

Save that configuration and then restart samba server and run by this command :

# /etc/init.d/samba restart 
[ ok ] Stopping Samba daemons: nmbd smbd.
[ ok ] Starting Samba daemons: nmbd smbd.
# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Global parameter security found in service section!
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

I think that's all I can tell about Install And Configure Samba Server For File Sharing. Hope you've enjoyed reading this tutorial as much I’ve enjoyed writing it. Please comment with feedback to support us. Thanks for visit.

Related Post

No comments:

Post a Comment