Sunday 11 November 2007

SMB:Configuring your computer as a server

A fairly comprehensive graphical Samba configuration tool is available for KDE, by installing the "kdenetwork-filesharing" package. Once install, you can find it by launching the KDE Control Center. (Alt-F2 and then type kcontrol). Browse to Internet & Network > Samba. It is fairly easy to use.

A less friendly but also graphical tool is Swat, a web-based interface.

The following tips show how to do some basic things without installing additional software, using the command line. It is not difficult, just be careful with typos.

First open a terminal: Applications > System Tools > Terminal and open the file smb.conf

sudo nano -w /etc/samba/smb.conf

How to Save: To save in nano use "ctrl/o" than "ctrl/x".

Tip: Replacing nano with gedit gives you a nice graphical editor.

The file *smb.conf* is divided in several sections:

Global Settings
Debugging/Accounting
Authentication
Printing
File sharing
Misc
Share Definitions

Let's start with Global Settings. Here you will see several lines, which you can also see in the graphical networktool like workgroup and wins server. If you changed everything to your liking already then you can skip this section, if not change to what you need. If you do not know what items mean, leave them be and read the [WWW] relevant part in the real Samba-howto instead of randomly changing them. It will save you trouble-shooting later.

The important part for us is File sharing. We need to change:

[homes]
comment = Home Directories
browseable = no

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

This describes your /home folder. Usually you want to share this folder in a home-environment, because these are the files you want to share. To do so, make the following changes:

[homes]
comment = Home Directories
browseable = yes

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

This finishes sharing your /home folder. The last thing we need to do is fixing a user.

Add users who can access your shares with the 'smbpasswd' command.

sudo  smbpasswd -a username

New SMB password:
Retype new SMB password:
Added user username.

NOTE: the username used here should be a real user setup on your PC/Server. Reload Samba for every change to users/passwords or 'smb.conf'

sudo /etc/init.d/samba reload

That's the basis of Samba file-sharing. Please leave your comments about what else is needed here.

Back to top

Complicating things a little

We started with the base of Samba file-sharing. The above-mentioned items should be enough to get you started. Next we will add details that you might or might not need.

Back to top

If you have more the one networkcard

If you have more the one networkcard (or interface) then you have to define where you want Samba to run. In smb.conf under the [global] section, add:

"interfaces = 127.0.0.1, 192.168.0.31/24"
"bind interfaces only = yes"

The first address (127.0.0.1), is a loopback network connection (it's your own machine). The second address (192.168.0.31), is the address of the card you want Samba to run on, the second number (24) is the subnet default for a CLASS-C network. It may vary depending on your network.

With "bind interfaces only" you limit which interfaces on a machine will serve SMB requests.

You can limit which IP address can connect to your Samba server adding these lines:

"hosts allow = 127.0.0.1, 192.168.0.31, 192.168.0.32"
"hosts deny = 0.0.0.0/0"

The loopback address must be present in the first line. The second line deny access from all IP address not in the first line.

Back to top

Sharing CUPS Printers

If You would like to share Your printers make the following changes to Samba:

If not already done create the Samba-user You want the share to be used by.

In smb.conf uncomment and change the lines ending up with the following configuration:

########## Printing ##########

# If you want to automatically load your printer list rather
# than setting them up individually then you'll need this
load printers = yes

# [...] // Some BSD printing stuff, do not edit if You do not need to

# CUPS printing. See also the cupsaddsmb(8) manpage in the
# cupsys-client package.
printing = cups
printcap name = cups

and in the Share Definitions section append and/or modify the [printers] part ending up like this:

# ======================= Share Definitions =======================
# [...] // File and Folder sharing, do not edit if You do not need to

[printers]
comment = All Printers
browseable = no
path = /tmp
printable = yes
public = yes
writable = no
create mode = 0700
printcap name = /etc/printcap
print command = /usr/bin/lpr -P%p -r %s
printing = cups

Some explanation what is done:

the [printers] part defines the default-behavior for all the printers that are mentioned in "printcap name". A sort of template how to create shares for these printers. This template is applied if "load printers" is set to true. For more detailed explanation refer to the Samba documentation.

And do not forget to reload Samba:

sudo /etc/init.d/samba reload

Back to top

1 comment:

Z. said...

大林,back to top链接不好使啊!^_^

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter