Linux basic configurations - linux samba en Slackware Linux samba server setup, installation and configuration <!-- google_ad_section_start --><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Linux has no problem sharing data and printer with Windows in networking environment. <b>Samba</b> 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 <a href="">Software Freedom Conservancy</a>. Samba has a long history in Linux and Windows file sharing. Everyone who uses Linux Samba program should read the chronology of Samba, the <a href="">10 years of Samba!</a> article written by Andrew Tridgell in January 2002. It shows how great and courage open source programmers are, doing jobs that benefits the world.</p> <p>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:</p> <ol><li>Install samba package.</li> <li>Configure samba server. </li> <li>Create samba users, groups, shared directory and set permissions. </li> <li>Create samba and set permissions.</li> <li>Start samba service.</li> <li>Testing and troubleshooting samba server and client.</li> </ol><h2>Install Linux samba package</h2> <p>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:</p> <table><tr><td><code>root@musang:~# <span style="color:red;">locate samba</span><br /> ...<br /> ...<br /> ...<br /> /var/spool/samba<br /> /etc/rc.d/rc.samba<br /> /etc/samba<br /> /etc/samba/smb.conf<br /> /etc/samba/private<br /> /etc/samba/private/secrets.tdb<br /> /etc/samba/private/smbpasswd<br /> /etc/samba/smb.conf-sample<br /> root@musang:~#<br /></code></td> </tr></table><p>You can also use slackpkg to search Linux samba package in the system:</p> <table><tr><td><code>root@musang:~# <span style="color:red;">slackpkg search samba</span><br /><br /> The list below shows all packages with the selected pattern.<br /><br /> [ installed ] - mozilla-thunderbird-<br /> [ installed ] - slackpkg-2.70.4-noarch-1<br /> ...<br /> ...<br /> ...<br /> [uninstalled] - kde-i18n-zh_TW-3.5.9-noarch-1<br /> [ upgrade ] - samba-3.0.32-i486-1_slack12.1 --&gt; samba-3.0.28a-i486-1<br /> [uninstalled] - lprng-3.8.28-i486-2<br /><br /> root@musang:~#<br /></code></td> </tr></table><p>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: </p> <table><tr><td><code>root@musang:~# <span style="color:red;">slackpkg install samba</span></code></td> </tr></table><p>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, or and install it using pkgtool.</p> <h2>Configure Linux samba server</h2> <p>Linux samba server configuration file is <b>smb.conf</b>. 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.</p> <p>Let's begin the samba configuration now. You must be root to do all these tasks. So change to root by issuing <b>su -</b> if you are not root yet. Slackware samba configuration file is in /etc/samba directory. Here are what you need to do first:</p> <p>1 - Change directory to /etc/samba.</p> <table><tr><td><code>root@musang:/etc/samba# <span style="color:red;">cd /etc/samba</span><br /></code></td> </tr></table><p>2 - Copy /etc/samba/smb.conf-sample to /etc/samba/smb.conf.</p> <table><tr><td><code><br /> root@musang:/etc/samba# <span style="color:red;">cp smb.conf-sample smb.conf</span><br /></code></td> </tr></table><p>3 - Edit smb.conf configuration file.</p> <table><tr><td><code>root@musang:/etc/samba# <span style="color:red;">vim smb.conf</span><br /></code></td> </tr></table><p>Here is how I set samba server for file sharing in my network for your reference:</p> <table><tr><td><code>#======================= Global Settings =====================================<br /> [global]<br /><br /> # workgroup = NT-Domain-Name or Workgroup-Name, eg: LINUX2<br /><span style="color:blue;"> workgroup = MYGROUP</span><br /><br /> # server string is the equivalent of the NT Description field<br /><span style="color:blue;">server string = Samba Server</span><br /><br /> # Security mode. Defines in which mode Samba will operate. Possible<br /> # values are share, user, server, domain and ads. Most people will want<br /> # user level security. See the Samba-HOWTO-Collection for details.<br /><span style="color:blue;">security = user</span><br /><br /> # This option is important for security. It allows you to restrict<br /> # connections to machines which are on your local network. The<br /> # following example restricts access to two C class networks and<br /> # the "loopback" interface. For more examples of the syntax see<br /> # the smb.conf man page<br /> ; hosts allow = 192.168.1. 192.168.2. 127.<br /><span style="color:blue;">hosts allow = 192.168.1. 127.</span><br /><br /> # this tells Samba to use a separate log file for each machine<br /> # that connects<br /><span style="color:blue;">log file = /var/log/samba.%m</span><br /><br /> # Put a capping on the size of the log files (in Kb).<br /><span style="color:blue;">max log size = 50</span><br /><br /> # DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names<br /> # via DNS nslookups. The default is NO.<br /><span style="color:blue;">dns proxy = no</span><br /><br /> #============================ Share Definitions ==============================<br /><span style="color:blue;">[homes]<br /> comment = Home Directories<br /> browseable = no<br /> writable = yes</span><br /><br /> # This one is useful for people to share files<br /><span style="color:blue;">[tmp]<br /> comment = Temporary file space<br /> path = /tmp<br /> read only = no<br /> public = yes</span><br /><br /> # A publicly accessible directory, but read only, except for people in<br /> # the "sales" group<br /><span style="color:blue;">[sales]<br /> comment = Public Stuff<br /> path = /home/samba<br /> public = yes<br /> writable = yes<br /> printable = no<br /> write list = @sales</span><br /></code></td> </tr></table><p>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.</p> <p>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 <b>testparm</b>. Here is the result of the above configuration: </p> <table><tr><td><code>root@musang:/etc/samba# <span style="color:red;">testparm</span><br /> Load smb config files from /etc/samba/smb.conf<br /> Processing section "[homes]"<br /> Processing section "[tmp]"<br /> Processing section "[sales]"<br /> Loaded services file OK.<br /> Server role: ROLE_STANDALONE<br /> Press enter to see a dump of your service definitions<br /><br /> [global]<br /> workgroup = MYGROUP<br /> server string = Samba Server<br /> log file = /var/log/samba.%m<br /> max log size = 50<br /> dns proxy = No<br /> wins support = Yes<br /> hosts allow = 192.168.1., 127.<br /><br /> [homes]<br /> comment = Home Directories<br /> read only = No<br /> browseable = No<br /><br /> [tmp]<br /> comment = Temporary file space<br /> path = /tmp<br /> read only = No<br /> guest ok = Yes<br /><br /> [sales]<br /> path = /usr/local/samba/public<br /> read only = No<br /> guest only = Yes<br /> guest ok = Yes<br /> root@musang:/etc/samba#<br /></code></td> </tr></table><h2>Create samba users, groups, shared directory and set permissions.</h2> <p>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:</p> <table><tr><td><code>root@musang:~# <span style="color:red;">smbpasswd -a labu</span><br /> New SMB password:<br /> Retype new SMB password:<br /> Failed to modify password entry for user labu<br /></code></td> </tr></table><p>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:</p> <table><tr><td><code>root@slackware:~# <span style="color:red;">smbpasswd -a labu</span><br /> New SMB password:<br /> Retype new SMB password:<br /> Added user labu.<br /> root@slackware:~#<br /></code></td> </tr></table><p>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.</p> <p>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:</p> <p>Add group, create a directory and change group owner and permission for that group: </p> <table><tr><td><code>root@musang:~# <span style="color:red;">groupadd sales</span><br /> root@musang:~# <span style="color:red;">mkdir /home/sales</span><br /> root@musang:~# <span style="color:red;">ls -l /home | grep sales</span><br /> drwxr-xr-x 2 root root 4096 2008-11-29 23:23 sales/<br /> root@musang:~# <span style="color:red;">chown sales.sales /home/sales</span><br /> root@musang:~# <span style="color:red;">ls -l /home | grep sales</span><br /> drwxr-xr-x 2 root sales 4096 2008-11-29 23:23 sales/<br /> root@musang:~# <span style="color:red;">chmod 775 /home/sales/</span><br /> root@musang:~# <span style="color:red;">ls -l /home | grep sales</span><br /> drwxrwxr-x 2 root sales 4096 2008-11-29 23:23 sales/<br /></code></td> </tr></table><p>Now we need to add users to the sales group. Here is how to do it:</p> <table><tr><td><code>root@musang:~# <span style="color:red;">usermod -g users -G sales labu</span><br /></code></td> </tr></table><p>We can check whether user labu has been added to the sales group in /etc/group: </p> <table><tr><td><code>root@musang:~# <span style="color:red;">cat /etc/group</span><br /></code></td> </tr></table><p>Make sure user you added is in the group, like this:</p> <table><tr><td><code>sales:x:102:labu<br /></code></td> </tr></table><h2>Start Linux samba service</h2> <p>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:</p> <p>Set 755 permissions for samba service:</p> <table><tr><td><code>root@musang:~# <span style="color:red;">chmod 755 /etc/rc.d/rc.samba</span><br /> root@musang:~# <span style="color:red;">ls -l /etc/rc.d/rc.samba</span><br /> -rwxr-xr-x 1 root root 791 2008-03-16 04:52 /etc/rc.d/rc.samba*<br /> root@musang:~#<br /></code></td> </tr></table><p>Now we can restart the service:</p> <table><tr><td><code>root@musang:~# <span style="color:red;">/etc/rc.d/rc.samba restart</span><br /> Starting Samba: /usr/sbin/smbd -D<br /> /usr/sbin/nmbd -D<br /> root@musang:~#<br /></code></td> </tr></table><h2>Testing and troubleshooting Linux samba server and client</h2> <p>We can query using nmblookup host: </p> <table><tr><td><code>root@musang:~# <span style="color:red;">nmblookup musang</span><br /> querying musang on<br /> musang<br /> root@musang:~#<br /></code></td> </tr></table><p>Test using smbclient: </p> <table><tr><td><code>luzar@musang:~$ <span style="color:red;">smbclient -L</span><br /> Password:<br /> Domain=[MUSANG] OS=[Unix] Server=[Samba 3.0.33]<br /><br /> Sharename Type Comment<br /> --------- ---- -------<br /> netlogon Disk Network Logon Service<br /> tmp Disk Temporary file space<br /> public Disk<br /> IPC$ IPC IPC Service (Samba Server)<br /> luzar Disk Home Directories<br /> Domain=[MUSANG] OS=[Unix] Server=[Samba 3.0.33]<br /><br /> Server Comment<br /> --------- -------<br /><br /> Workgroup Master<br /> --------- -------<br /> MYGROUP MUSANG<br /> luzar@musang:~$<br /></code></td> </tr></table><p>Testing from windows client computer:</p> <p>1 - Open MyNetwork Places. </p> <p><a href="" title="Image" target="_blank"><img src="" alt="MyNetwork Places screenshot" /></a></p> <p>2 - Other Places. If you haven't set Microsoft Windows Network, it'll be there.</p> <p><a href="" title="Image" target="_blank"><img src="" alt="Other Places screenshot" /></a></p> <p>3 - Microsoft Windows Network.</p> <p><a href="" title="Image" target="_blank"><img src="" alt="Microsoft Windows Network screenshot" /></a></p> <p>That's all. Good luck setting up your own Linux samba server.</p> </div></div></div><!-- google_ad_section_end --><div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above"><div class="field-label">Tags:&nbsp;</div><div class="field-items"><div class="field-item even" rel="dc:subject"><a href="/taxonomy/term/19" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">linux samba</a></div><div class="field-item odd" rel="dc:subject"><a href="/taxonomy/term/16" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">linux server</a></div></div></div> Sat, 29 Nov 2008 06:41:54 +0000 jinlusuh 123 at