<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.freebsdwiki.net/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.freebsdwiki.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Honk</id>
		<title>FreeBSDwiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://www.freebsdwiki.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Honk"/>
		<link rel="alternate" type="text/html" href="http://www.freebsdwiki.net/index.php/Special:Contributions/Honk"/>
		<updated>2026-04-09T20:51:36Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.18.0</generator>

	<entry>
		<id>http://www.freebsdwiki.net/index.php/Samba,_Configuration</id>
		<title>Samba, Configuration</title>
		<link rel="alternate" type="text/html" href="http://www.freebsdwiki.net/index.php/Samba,_Configuration"/>
				<updated>2004-12-03T21:24:23Z</updated>
		
		<summary type="html">&lt;p&gt;Honk: correcting a typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article will walk you through a quick setup of [[Samba]] - creating directories to be shared, telling Samba to share those directories, how to limit access to different shares, and finally, how to set up a windows machine to have unfettered access to appropriate shares based on the currently logged in user. This article assumes you have a fresh, unconfigured [[Samba Installation]] to work with.&lt;br /&gt;
&lt;br /&gt;
== Setting up your shares on the machine ==&lt;br /&gt;
&lt;br /&gt;
First we need to decide what we're going to share, or at the very least, where the shares will actually reside. The simplest way to do this is to simply create a new directory in an easy to remember place, say, '''/usr'''. You can either share that new folder directly, or create several new directories within it, and limit access to each directory based on criteria I will make clear later in this article. For now, let's assume you have two sets of documents, public and private, and that you want to limit users' access to those documents based on who they are - they can either access both, or just public. So:&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''mkdir /usr/smbroot'''&lt;br /&gt;
 Oyabun# '''mkdir /usr/smbroot/public'''&lt;br /&gt;
 Oyabun# '''mkdir /usr/smbroot/private'''&lt;br /&gt;
&lt;br /&gt;
The first command creates the '''/usr/smbroot/''' directory, which will hold all of your shares. The second command creates the public directory, which '''all''' users will be able to access, and the third command creates the private directory, which only '''select''' users will be able to access.&lt;br /&gt;
&lt;br /&gt;
Now we need to set [[permissions]] on these directories. The [[permissions]] article goes into great detail about permissions, but a quick run through here will be fine. We'll use [[chown]] to change ownership of these two directories now. We'll assume you have or will set up two groups for your users, one group named '''public''', and another named '''private'''.&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''chown :public /usr/smbroot/public'''&lt;br /&gt;
 Oyabun# '''chown :private /usr/smbroot/private'''&lt;br /&gt;
&lt;br /&gt;
The first command sets the owning group of /usr/smbroot/public to :public. The second command assigns ownership of /usr/smbroot/private to the group :private.&lt;br /&gt;
&lt;br /&gt;
Now we need to set the actual [[permissions]] with [[chmod]].&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''chmod 770 /usr/smbroot/public'''&lt;br /&gt;
 Oyabun# '''chmod 770 /usr/smbroot/private'''&lt;br /&gt;
&lt;br /&gt;
Same [[permissions]] for each directory, broken down thusly: The first '''7''' is the 'owner' flag, and 7 means read/write/execute. The owner can do all of those things. The second '''7''' is the group flag, meaning the owning :group can also r/w/x. The third character, '''0''', is in the 'rest of the world' position, meaning anyone who is NOT the owner, and NOT a member of the owning group. They can't read, they can't write, and they can't execute. Since we're not setting up anonymous access, we don't want users who aren't explicitly defined as having access to actually have any access, and this will accomplish that.&lt;br /&gt;
&lt;br /&gt;
== Configuring Samba to use your shares and interface with local Win.X machines ==&lt;br /&gt;
&lt;br /&gt;
Ok, now we have the shares set up appropriately, we just need to define them for Samba. In '''/usr/local/etc/''', there is a file named &amp;quot;'''smb.conf.default'''&amp;quot;. This is a seriously large and complex file with waaaay more options than the average user will ever need to get Samba up and running. I highly suggest you go through it, as it has several examples of methods used to share directories, and access restriction methods. For this article, we'll be writing an [[smb.conf]] from scratch.&lt;br /&gt;
&lt;br /&gt;
'''[global]'''&lt;br /&gt;
&lt;br /&gt;
The first section of your new [[smb.conf]] file should look like this:&lt;br /&gt;
&lt;br /&gt;
 [global]&lt;br /&gt;
 workgroup = WORKGROUP&lt;br /&gt;
 server string = NameOfServer&lt;br /&gt;
 log file = /var/log/log.%m&lt;br /&gt;
 max log size = 50&lt;br /&gt;
 security = user&lt;br /&gt;
 encrypt passwords = yes&lt;br /&gt;
 socket options = TCP_NODELAY&lt;br /&gt;
 preferred master = yes&lt;br /&gt;
&lt;br /&gt;
'''[global]''' is a header in the file, telling Samba all entries after that, before the next [section] are to be globally applied.&lt;br /&gt;
&lt;br /&gt;
'''workgroup = WORKGROUP''' - Specifies which Windows Workgroup to make the server a member of.&lt;br /&gt;
&lt;br /&gt;
'''server string = NameOfServer''' - Names the server. This is the name you'll see in network neighborhood. For example, my smb.conf names my server 'Oyabun'. (cuz it's the boss!)&lt;br /&gt;
&lt;br /&gt;
'''log file = /var/log/log%m''' - Tells Samba to create log files for each machine that connects in the var/log/ directory. For example, if a machine with the name of ''johndesktop'' connected, a log file named '''log.johndesktop''' would be created in /var/log, and appropriate entries for that machine would be made there.&lt;br /&gt;
&lt;br /&gt;
'''max log size = 50''': limits the size of each log files to x kilobytes, in this case 50. This is so you don't find a gig of logs a year down the road.&lt;br /&gt;
&lt;br /&gt;
'''security = user''': This is '''important''', and integral to simple networking between your new Samba server and your Windows machines.&lt;br /&gt;
&lt;br /&gt;
'''ecrypt passwords = yes''': This is also '''important''' - passwords must be encrypted for each machine to successfuly negotiate login credentials with your Samba server.&lt;br /&gt;
&lt;br /&gt;
'''socket options = TCP_NODELAY''': This is not required, but the Samba documentation within smb.conf.default suggests this may yield better performance, so I include it.&lt;br /&gt;
&lt;br /&gt;
'''preferred master = yes''': Windows machines &amp;quot;elect&amp;quot; master browsers, which is a machine which takes on the duties of describing to other machines what all the machine names and locations are. Since your Samba machine is likely to be the sanest machine on your network, it's a good idea to have it 'fudge' the election results and always be the master browser. This option causes Samba to force a browser election when it starts up, and cheats to give it a higher chance of 'winning'.&lt;br /&gt;
&lt;br /&gt;
And that's the global section. Now, on to actually setting up shares.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''[homes]'''&lt;br /&gt;
&lt;br /&gt;
If you want your users to be able to access the home directories of their FreeBSD user accounts, add a [homes] section. If you do NOT want individual users to have private storage areas, do not include this section.&lt;br /&gt;
&lt;br /&gt;
 [homes]&lt;br /&gt;
 comment = Home Directories&lt;br /&gt;
 browseable = no&lt;br /&gt;
 writeable = yes&lt;br /&gt;
&lt;br /&gt;
The mere existence of [homes] tells Samba to allow users to have access to their home directories via network sharing. If it's not there, they don't have it.&lt;br /&gt;
&lt;br /&gt;
'''comment = Home Directories''' is a description for the [section], and will show up in Windows Explorer under the 'comment' field.&lt;br /&gt;
&lt;br /&gt;
'''browseable = no''' means users other than the owner can't see or browse the share. (I can't see your home directory, you can't see mine, but we're both valid users.) Similar in purpose and execution to the 'My Documents' folder Windows users are familiar with. Each user has their own 'My Documents' folder.&lt;br /&gt;
&lt;br /&gt;
'''writeable = yes''' means users can save files in their home directories from across the network.&lt;br /&gt;
&lt;br /&gt;
That's it, setting up home directories is simple.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''[public]'''&lt;br /&gt;
&lt;br /&gt;
Now we'll set up the publicly accessible folder, located at '''/usr/smbroot/public/'''.&lt;br /&gt;
&lt;br /&gt;
 [public]&lt;br /&gt;
 comment = Public&lt;br /&gt;
 path = /usr/smbroot/public&lt;br /&gt;
 public = no&lt;br /&gt;
 writeable = yes&lt;br /&gt;
 write list = @public&lt;br /&gt;
 directory mask = 0770&lt;br /&gt;
 create mask = 0770&lt;br /&gt;
&lt;br /&gt;
'''[public]''': Create a new share named 'Public', which will look like a folder named 'Public' in Network Neighborhood.&lt;br /&gt;
&lt;br /&gt;
'''comment = Public''': Same deal, this fills the 'comment' field in windows explorer / network neighborhood, when you're looking at the share.&lt;br /&gt;
&lt;br /&gt;
'''path = /usr/smbroot/public''': This tells samba exactly where on the local machine to store files for this share. This is pretty important.&lt;br /&gt;
&lt;br /&gt;
'''public = no''': This is sort of counter-intuitive, but you don't want this set to yes.&lt;br /&gt;
&lt;br /&gt;
'''writeable = yes''': This tells Samba to let authorized users write to the directory.&lt;br /&gt;
&lt;br /&gt;
'''write list = @public''': Lists the ''users'' and ''@groups'' allowed to write here. This is important! To define this further, or add more users or @groups, you'd write the line like this:&lt;br /&gt;
&amp;quot;valid users = joe bill @public @friends @dogs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
'''directory mask = 0750''': The directory mask setting controls the '''most permissive''' setting Windows clients are allowed to give a directory.  In this example, the mask is set to 750, so a client can set read, write, and execute permissions to anything it wants to for the directory's owner; but for the group the Windows client can only set read and execute permissions, and since the &amp;quot;world&amp;quot; bit is set to 0, the Windows client will be unable to set any allowable permissions at all for &amp;quot;world&amp;quot; (neither the owner nor the group) for that directory.  Note that the windows client is free to set ''less'' permissive settings on the directory - if it wanted to, it could still deny access to the owner or group; it just can't ''give'' access more permissive than that specified by the mass.&lt;br /&gt;
&lt;br /&gt;
'''create mask = 0750''': Same deal, only this applies to files.&lt;br /&gt;
&lt;br /&gt;
That's it - you've defined all the important parts of the share for Samba, so it knows where to find it, and how to limit users' access to it.&lt;br /&gt;
&lt;br /&gt;
Test your new config with [[testparm]], which is a Samba tool that lets you validate your smb.conf.&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''testparm''' &lt;br /&gt;
&lt;br /&gt;
I won't list the results here, but you should see a list of your shares. If there are any warnings or error messages, you'll want to analyze and correct the problem. Lastly, testparm will dump your smb.conf to the console.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
'''[private]'''&lt;br /&gt;
&lt;br /&gt;
Now we'll set up the private share. It will actually look just like the public share, with a few small changes.&lt;br /&gt;
&lt;br /&gt;
 [private]&lt;br /&gt;
 comment = Private&lt;br /&gt;
 path = /usr/smbroot/private&lt;br /&gt;
 public = no&lt;br /&gt;
 writeable = yes&lt;br /&gt;
 valid users = @private&lt;br /&gt;
 write list = @private&lt;br /&gt;
 directory mask = 0770&lt;br /&gt;
 create mask = 0770&lt;br /&gt;
&lt;br /&gt;
Obviously we defined the basic stuff like [private] and where the directory is.&lt;br /&gt;
&lt;br /&gt;
'''valid users = @private''' - This prevents anyone who is not a member of @private from having access to this share. Because '''public = no''', people who are NOT members of @private won't even see this share when they browse the server.&lt;br /&gt;
&lt;br /&gt;
That's it, you now have two distinct shares set up, with two distinct sets of criteria to determine who gets access to those shares from a windows machine.&lt;br /&gt;
&lt;br /&gt;
== User accounts in BSD, Samba, and Windows ==&lt;br /&gt;
&lt;br /&gt;
There are two parts to this step, adding matching matching user accounts to the Samba server and the various windows machines, and adding matching Samba passwords to the Samba server for each user. '''Usernames and passwords must match exactly between the client Windows machines and the Samba server.'''&lt;br /&gt;
&lt;br /&gt;
Let's say ''Bob'' logs onto his windows machine with the username &amp;quot;''bob''&amp;quot; and the password &amp;quot;''syeruncle''&amp;quot;. He already has an existing windows account, obviously, so you don't need to set that up, but if he didn't, you would. Bob is going to be a member of the @public group, and Greg will be a member of @private.&lt;br /&gt;
&lt;br /&gt;
The quickest way to do this is to use '''/stand/[[sysinstall]]''' to add the user. You can also add users via the command line with [[adduser]] or [[pw]]. Make sure you are root before trying to add user accounts or Samba accounts, and remember to make each user a member of the appropriate group!&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''pw useradd bob -g public'''&lt;br /&gt;
 Oyabun# '''pw useradd greg -g private''' &lt;br /&gt;
&lt;br /&gt;
Now we need to use [[smbpasswd]] to validate these users in the eyes of Samba.&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''smbpasswd -a bob'''&lt;br /&gt;
 New SMB password:&lt;br /&gt;
 Retype new SMB password:&lt;br /&gt;
 Password changed for user bob.&lt;br /&gt;
&lt;br /&gt;
In this example, as root, I used the [[smbpasswd]] command to create a Samba account for ''bob''. It then asked me to enter a password for the new user, asked me to confirm it, and announced that the password was changed.&lt;br /&gt;
&lt;br /&gt;
Repeat this process for ''greg'', entering greg's password.&lt;br /&gt;
&lt;br /&gt;
If ''greg'' and ''bob'' are not really unix users at all, but only windows users that you want to be able to access Samba shares, you may wish to consider making sure they can't use the system accounts you created for them to actually log in to the box.  For example:&lt;br /&gt;
&lt;br /&gt;
 Oyabun# '''[[pw]] usermod bob -s /sbin/nologin'''&lt;br /&gt;
 Oyabun# '''su bob'''&lt;br /&gt;
 This account is currently not available.&lt;br /&gt;
 Oyabun#&lt;br /&gt;
&lt;br /&gt;
In this example, we set the ''bob'' account's default shell to /sbin/nologin, and then checked to make sure that account really couldn't shell into the box by using [[su]] to see what would happen if someone tried.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
Finally, we're done. We have shares set up, user accounts are in place, and everything is ready to go - now we just have to start Samba. This is easy. A startup script was placed in &amp;quot;'''/usr/local/etc/rc.d/'''&amp;quot;, with a likely name of &amp;quot;''samba.sh.default''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Let's rename it, and run it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Oyabun# cd /usr/local/etc/rc.d&lt;br /&gt;
Oyabun# mv samba.sh.default samba.sh&lt;br /&gt;
Oyabun# /usr/local/etc/rc.d/samba start&lt;br /&gt;
SambaOyabun#&lt;br /&gt;
Oyabun#&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First, rename the file from samba.sh.default to samba.sh. Then, execute it, using the full path (it will complain otherwise). If all  went well, after execting ''samba.sh start'', you'll see ''Samba'' inserted before the name of your server at the next shell prompt.  This means Samba is indeed running, and that you can now attempt to connect to this machine from your Windows machines. You should do so, testing the various accounts you have set up to make sure they can all connect.&lt;br /&gt;
&lt;br /&gt;
Congrats, you now have a Samba server.&lt;br /&gt;
&lt;br /&gt;
See also: [[Samba]] - [[Samba_Installation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Common Tasks]] [[Category:Configuring FreeBSD]]&lt;/div&gt;</summary>
		<author><name>Honk</name></author>	</entry>

	</feed>