How to Setup Samba server and Allow File Sharing in Linux/Windows Clients
To Setup Samba server and Allow File Sharing on Linux/Windows Clients
Samba is an open source software which uses TCP protocol. Samba provides file and print services to SMB/CIFS clients, which allow the clients to see the server as if it was a Windows system. This article explains the procedure to Setup Samba server and Allow File Sharing on Linux/Windows Clients.
To Install the Samba Server
The testing environment consists of two Ubuntu 14.04 boxes and one Windows 7 machine.
- Samba / NFS server [box1 (Ubuntu 14.04) : 192.168.5.148],
- Samba client #1 [box2 (Ubuntu 14.04) : 192.168.5.147],
- Samba client #2 [Windows 7 machine : 192.168.5.22]
Install the following packages on box1.
root@linuxhelp:~# sudo apt-get install samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libntdb1 python-ntdb
Use ' apt-get autoremove' to remove them.
Suggested packages:
bind9 bind9utils ldb-tools ntp smbldap-tools winbind
The following NEW packages will be installed:
samba
.
.
.
Rules updated for profile ' Samba'
Firewall reloaded
Processing triggers for man-db (2.7.4-1) ...
Setting up samba (2:4.3.8+dfsg-0ubuntu0.15.10.2) ...
Processing triggers for libc-bin (2.21-0ubuntu4) ...On the box2.
To Setup the File Sharing Through Samba server
To Configure Samba Share
Open the configuration file ' /etc/samba/smb.conf' then add the section for our share. Here we are configuring two share groups namely open and global1 for the users user40 and user42.
root@linuxhelp:~# vim /etc/samba/smb.conf
[open]
path = /home/user40
browseable = yes
read only = yes
valid users = user40
hosts allow = 192.168.5.
[global1]
available = yes
path = /home/user42
browseable = yes
read only = no
writeable = yes
valid users = user42
hosts allow = 192.168.5.
Save the file and test it by using the ' testparm' utility.
root@linuxhelp:~# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The " syslog" option is deprecated
Processing section " [printers]"
Processing section " [print$]"
Processing section " [open]"
Processing section " [global1]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[open]
path = /home/user40
valid users = user40
hosts allow = 192.168.5.
[global1]
path = /home/user42
valid users = user42
read only = No
hosts allow = 192.168.5.
To Add Samba Users
Add the system users, set permissions and ownership.
root@linuxhelp:~# useradd user40
root@linuxhelp:~# useradd user42
Now set password and enable the users.
root@linuxhelp:~# sudo smbpasswd -a user40 New SMB password: Retype new SMB password: root@linuxhelp:~# sudo smbpasswd -a user42 New SMB password: Retype new SMB password: root@linuxhelp:~# sudo smbpasswd -e user40 Enabled user user40. root@linuxhelp:~# sudo smbpasswd -e user42 Enabled user user42.
Now restart and enable samba services.
root@linuxhelp:~# sudo service smbd restart
root@linuxhelp:~# sudo service smbd enable
To Install the SAMBA client
Install the following packages on box2. Here, smbclient package is to check the connection between server and client, whereas cifs package helps in sharing files and directories.
root@linuxhelp:~# sudo apt-get install smbclient
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libavahi-client-dev libavahi-common-dev libavahi-compat-libdnssd1
libdbus-1-dev libjs-jquery libntdb1 libruby2.1 libyaml-0-2 python-ntdb
ruby2.1 rubygems-integration
Use ' apt-get autoremove' to remove them.
The following extra packages will be installed:
libldb1 libsmbclient libwbclient0 python-ldb python-samba samba-common
samba-common-bin samba-libs
.
.
.
Setting up smbclient (2:4.3.8+dfsg-0ubuntu0.15.10.2) ...
Processing triggers for libc-bin (2.21-0ubuntu4) ...
root@linuxhelp:~# sudo apt-get install cifs*
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting ' cifer' for regex ' cifs*'
Note, selecting ' libjcifs-java' for regex ' cifs*'
Note, selecting ' libjcifs-java-doc' for regex ' cifs*'
Note, selecting ' telepathy-specification' for regex ' cifs*'
Note, selecting ' cifs-utils' for regex ' cifs*'
The following packages were automatically installed and are no longer required:
libavahi-client-dev libavahi-common-dev libavahi-compat-libdnssd1
libdbus-1-dev libntdb1 libruby2.1 libyaml-0-2 python-ntdb ruby2.1
rubygems-integration
Use ' apt-get autoremove' to remove them.
The following extra packages will be installed:
keyutils
Suggested packages:
winbind
The following NEW packages will be installed:
cifer cifs-utils keyutils libjcifs-java libjcifs-java-doc
.
.
.
Setting up cifer (1.2.0-0ubuntu3) ...
Setting up cifs-utils (2:6.4-1ubuntu1) ...
Setting up keyutils (1.5.9-5ubuntu1) ...
Setting up libjcifs-java (1.3.18-2) ...
Setting up libjcifs-java-doc (1.3.18-2) ...
Setting up telepathy-specification (0.27.3-1) ...
To Mount the Samba Share in LINUX
On client side Box2
Now check the access of the network share for the user40 and user42.
root@linuxhelp:~# smbclient -L //192.168.5.148/open -U user40
WARNING: The " syslog" option is deprecated
Enter user40' s password:
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.3.8-Ubuntu]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
open Disk
global1 Disk
IPC$ IPC IPC Service (linuxhelp server (Samba, Ubuntu))
Microsoft_XPS_Document_Writer:1 Printer Microsoft XPS Document Writer
Fax:2 Printer Fax
Send_To_OneNote_2010:1 Printer Send To OneNote 2010
Fax:3 Printer Fax
Microsoft_XPS_Document_Writer:2 Printer Microsoft XPS Document Writer
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.3.8-Ubuntu]
Server Comment
--------- -------
ADMIN-62
LINUXHELP linuxhelp server (Samba, Ubuntu)
Workgroup Master
--------- -------
WORKGROUP ADMIN-62
root@linuxhelp:~# smbclient -L //192.168.5.148/global1 -U user42
WARNING: The " syslog" option is deprecated
Enter user42' s password:
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.3.8-Ubuntu]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
open Disk
global1 Disk
IPC$ IPC IPC Service (linuxhelp server (Samba, Ubuntu))
Microsoft_XPS_Document_Writer:1 Printer Microsoft XPS Document Writer
Fax:2 Printer Fax
Send_To_OneNote_2010:1 Printer Send To OneNote 2010
Fax:3 Printer Fax
Microsoft_XPS_Document_Writer:2 Printer Microsoft XPS Document Writer
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.3.8-Ubuntu]
Server Comment
--------- -------
ADMIN-62
LINUXHELP linuxhelp server (Samba, Ubuntu)
Workgroup Master
--------- -------
WORKGROUP ADMIN-62
To Set a temporary mount point
root@linuxhelp:~# mount //192.168.5.148/open /mnt -o username=user40 Password for user40@//192.168.5.148/open: *** root@linuxhelp:~# df -h Filesystem Size Used Avail Use% Mounted on udev 476M 0 476M 0% /dev tmpfs 99M 5.4M 94M 6% /run /dev/sda3 28G 4.0G 22G 16% / tmpfs 493M 156K 492M 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/sda1 453M 54M 373M 13% /boot cgmfs 100K 0 100K 0% /run/cgmanager/fs tmpfs 99M 56K 99M 1% /run/user/1000 //192.168.5.148/open 28G 4.1G 22G 16% /mnt
To set a Permanent mount
Add the following entry in ' /etc/fstab' file.
# /etc/fstab: static file system information. . . . /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0 //192.168.5.148/global1 /mnt cifs defaults,credentials=/file2.txt 0 0
The file ' /file2.txt' that contains the two lines which indicates the username and password of an account which is allowed to use the share.
root@linuxhelp:/# vim file2.txt
username=user42
password=123
root@linuxhelp:~# mount -a
root@linuxhelp:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 476M 0 476M 0% /dev
tmpfs 99M 5.4M 94M 6% /run
/dev/sda3 28G 4.0G 22G 16% /
tmpfs 493M 156K 492M 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 493M 0 493M 0% /sys/fs/cgroup
/dev/sda1 453M 54M 373M 13% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 99M 56K 99M 1% /run/user/1000
//192.168.5.148/open 28G 4.1G 22G 16% /mnt
//192.168.5.148/global1 28G 4.1G 22G 16% /mnt
To Mount the Samba Share in Windows
Open the windows explorer to mount the samba share in windows.
Now type the IP address of the samba server in the address bar.
Now right click on the share and click Map network drive.
Assign the drive to be mapped and click Finish.
Now the samba share global1 has been successfully mounted in windows system.
Comments ( 0 )
No comments available