Slackware Linux samba server setup, installation and configuration
Linux has no problem sharing data and printer with Windows in networking environment. Samba is a Linux service that provides file and printer sharing between Linux and Windows system. It can even be a Primary Domain Controller (PDC). Samba is developed by The Samba project team which is a member of the Software Freedom Conservancy. Samba has a long history in Linux and Windows file sharing. Everyone who uses Linux Samba program should read the chronology of Samba, the 10 years of Samba! article written by Andrew Tridgell in January 2002. It shows how great and courage open source programmers are, doing jobs that benefits the world.
In this tutorial, we are going to learn how to setup Linux samba server for file sharing in windows networking environment. Here is a list of steps involves in setting up a Linux samba server:
- Install samba package.
- Configure samba server.
- Create samba users, groups, shared directory and set permissions.
- Create samba and set permissions.
- Start samba service.
- Testing and troubleshooting samba server and client.
Install Linux samba package
The first thing we need to do is to check whether samba package is already installed in our system. We can use locate command to find samba. Here is an example of locate command run in Slackware:
root@musang:~# locate samba
...
...
...
/var/spool/samba
/etc/rc.d/rc.samba
/etc/samba
/etc/samba/smb.conf
/etc/samba/private
/etc/samba/private/secrets.tdb
/etc/samba/private/smbpasswd
/etc/samba/smb.conf-sample
root@musang:~#
You can also use slackpkg to search Linux samba package in the system:
root@musang:~# slackpkg search samba
The list below shows all packages with the selected pattern.
[ installed ] - mozilla-thunderbird-2.0.0.18-i686-1
[ installed ] - slackpkg-2.70.4-noarch-1
...
...
...
[uninstalled] - kde-i18n-zh_TW-3.5.9-noarch-1
[ upgrade ] - samba-3.0.32-i486-1_slack12.1 --> samba-3.0.28a-i486-1
[uninstalled] - lprng-3.8.28-i486-2
root@musang:~#
Don't worry if samba has not been installed in your system. Here is an example of how to install Linux samba package in Slackware:
root@musang:~# slackpkg install samba
If you didn't install slackpkg, use Slackware pkgtool to install samba from Slackware installation dvd. You can also download the latest samba package from Slackware official website, slackbuild.org or linuxpackages.net and install it using pkgtool.
Configure Linux samba server
Linux samba server configuration file is smb.conf. To configure a samba server for file sharing, we just need to edit smb.conf. Fortunately, configuring Linux servers, including samba server has been made easy for us by those kind open source programmers out there. All setup and configuration already there, so we just need to uncomment and tweak a little bit to suit our network.
Let's begin the samba configuration now. You must be root to do all these tasks. So change to root by issuing su - if you are not root yet. Slackware samba configuration file is in /etc/samba directory. Here are what you need to do first:
1 - Change directory to /etc/samba.
root@musang:/etc/samba# cd /etc/samba
2 - Copy /etc/samba/smb.conf-sample to /etc/samba/smb.conf.
root@musang:/etc/samba# cp smb.conf-sample smb.conf
3 - Edit smb.conf configuration file.
root@musang:/etc/samba# vim smb.conf
Here is how I set samba server for file sharing in my network for your reference:
#======================= Global Settings ===================================== [global] # workgroup = NT-Domain-Name or Workgroup-Name, eg: LINUX2 workgroup = MYGROUP # server string is the equivalent of the NT Description field server string = Samba Server # Security mode. Defines in which mode Samba will operate. Possible # values are share, user, server, domain and ads. Most people will want # user level security. See the Samba-HOWTO-Collection for details. security = user # This option is important for security. It allows you to restrict # connections to machines which are on your local network. The # following example restricts access to two C class networks and # the "loopback" interface. For more examples of the syntax see # the smb.conf man page ; hosts allow = 192.168.1. 192.168.2. 127. hosts allow = 192.168.1. 127. # this tells Samba to use a separate log file for each machine # that connects log file = /var/log/samba.%m # Put a capping on the size of the log files (in Kb). max log size = 50 # DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names # via DNS nslookups. The default is NO. dns proxy = no #============================ Share Definitions ============================== [homes] comment = Home Directories browseable = no writable = yes # This one is useful for people to share files [tmp] comment = Temporary file space path = /tmp read only = no public = yes # A publicly accessible directory, but read only, except for people in # the "sales" group [sales] comment = Public Stuff path = /home/samba public = yes writable = yes printable = no write list = @sales
That is a basic file sharing configuration. I didn't add anything. Just uncomment configuration I need for my network, and set shared directory path and name. I also didn't allow printer sharing in this configuration.
Now we need to test smb.conf for any error although we didn't do much editing in the file. The command for checking smb.cof configuration file is testparm. Here is the result of the above configuration:
root@musang:/etc/samba# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[tmp]"
Processing section "[sales]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
workgroup = MYGROUP
server string = Samba Server
log file = /var/log/samba.%m
max log size = 50
dns proxy = No
wins support = Yes
hosts allow = 192.168.1., 127.
[homes]
comment = Home Directories
read only = No
browseable = No
[tmp]
comment = Temporary file space
path = /tmp
read only = No
guest ok = Yes
[sales]
path = /usr/local/samba/public
read only = No
guest only = Yes
guest ok = Yes
root@musang:/etc/samba#
Create samba users, groups, shared directory and set permissions.
Samba users are independent from Linux system users and groups. That means they are not sharing the /etc/passwd users. So you need to create samba users again and give them password. Here is how to do it:
root@musang:~# smbpasswd -a labu
New SMB password:
Retype new SMB password:
Failed to modify password entry for user labu
Why do I failed to create user for samba? That's because samba user must first be a Linux system user. So create an account for a samba user in Linux system first then create a samba account:
root@slackware:~# smbpasswd -a labu
New SMB password:
Retype new SMB password:
Added user labu.
root@slackware:~#
When you successfully created a samba user account, the database about user account and password is kept in /etc/samba/private/smbpasswd file. This is only applicable for Slackware Linux. Other distribution could be different.
If you want to give permission only for a certain people, you can create a group for them to use a certain directory. Create that certain directory. Then, you can set permissions and ownership for that group to use the directory. Here is a step by step on how to do it:
Add group, create a directory and change group owner and permission for that group:
root@musang:~# groupadd sales root@musang:~# mkdir /home/sales root@musang:~# ls -l /home | grep sales drwxr-xr-x 2 root root 4096 2008-11-29 23:23 sales/ root@musang:~# chown sales.sales /home/sales root@musang:~# ls -l /home | grep sales drwxr-xr-x 2 root sales 4096 2008-11-29 23:23 sales/ root@musang:~# chmod 775 /home/sales/ root@musang:~# ls -l /home | grep sales drwxrwxr-x 2 root sales 4096 2008-11-29 23:23 sales/
Now we need to add users to the sales group. Here is how to do it:
root@musang:~# usermod -g users -G sales labu
We can check whether user labu has been added to the sales group in /etc/group:
root@musang:~# cat /etc/group
Make sure user you added is in the group, like this:
sales:x:102:labu
Start Linux samba service
If everything is ready, then it's time to start Linux samba service. The samba server is a standalone server, so you have to make it executable before start the service. Here is all the steps that you should do to restart Linux samba service:
Set 755 permissions for samba service:
root@musang:~# chmod 755 /etc/rc.d/rc.samba root@musang:~# ls -l /etc/rc.d/rc.samba -rwxr-xr-x 1 root root 791 2008-03-16 04:52 /etc/rc.d/rc.samba* root@musang:~#
Now we can restart the service:
root@musang:~# /etc/rc.d/rc.samba restart
Starting Samba: /usr/sbin/smbd -D
/usr/sbin/nmbd -D
root@musang:~#
Testing and troubleshooting Linux samba server and client
We can query using nmblookup host:
root@musang:~# nmblookup musang
querying musang on 192.168.1.255
192.168.1.3 musang
root@musang:~#
Test using smbclient:
luzar@musang:~$ smbclient -L 192.168.1.3
Password:
Domain=[MUSANG] OS=[Unix] Server=[Samba 3.0.33]
Sharename Type Comment
--------- ---- -------
netlogon Disk Network Logon Service
tmp Disk Temporary file space
public Disk
IPC$ IPC IPC Service (Samba Server)
luzar Disk Home Directories
Domain=[MUSANG] OS=[Unix] Server=[Samba 3.0.33]
Server Comment
--------- -------
Workgroup Master
--------- -------
MYGROUP MUSANG
luzar@musang:~$
Testing from windows client computer:
1 - Open MyNetwork Places.
2 - Other Places. If you haven't set Microsoft Windows Network, it'll be there.
3 - Microsoft Windows Network.
That's all. Good luck setting up your own Linux samba server.
