Difference between revisions of "Samba"

From ArchWiki
Jump to: navigation, search
m (Accessing Samba Shares)
(Share files for your LAN without user and password)
Line 106: Line 106:
  
 
  [Public Share]
 
  [Public Share]
 +
path = /path/to/public/share
 +
available = yes
 +
browsable = yes
 +
public = yes
 +
writable = no
 +
 +
=== Sample configuration file ===
 +
The configuration that worked for me:
 +
[global]
 +
workgroup = WORKGROUP
 +
server string = Samba Server
 +
netbios name = PC_NAME
 +
security = share
 +
; the line below is important! If you have permission issues make sure the user here is the same as the user of the folder you want to share
 +
guest account = mark
 +
username map = /etc/samba/smbusers
 +
name resolve order = hosts wins bcast
 +
wins support = no<br />
 +
[public]
 +
comment = Public Share
 
  path = /path/to/public/share
 
  path = /path/to/public/share
 
  available = yes
 
  available = yes

Revision as of 21:57, 15 September 2009

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end


Introduction

Samba is a re-implementation of the SMB/CIFS networking protocol, it facilitates file and printer sharing between Linux and Windows systems.

Installation

To install the Samba server, install the samba package

# pacman -S samba

Configuration

As root, copy the default Samba configuration file to /etc/samba/smb.conf

# cp /etc/samba/smb.conf.default /etc/samba/smb.conf

Open the smb.conf and edit it to suit your needs. The file is well commented and provides many examples, it shouldn't be too hard to understand.

The default file creates a share for each user's home directory. It also creates a share for printers.

Starting the Daemon

Samba can be started with

# /etc/rc.d/samba start

Samba typically uses FAM to monitor the filesystem for changes. You will need to have the fam daemon started before samba. A better alternative is to use Gamin

Add samba to your DAEMONS line in rc.conf to start the daemon at boot

Adding Users

To log into a Samba share you'll need to add a user.

# smbpasswd -a <user>

The user must already have a account on the server. If the user does not exist you will recieve the error:

Failed to modify password entry for user "<user>"

You can add a new user to the system with adduser.


Accessing Samba Shares

KDE and Gnome have the ability to browse Samba shares. You therefore do not need any additional packages if using either of these DE's. If however you plan to use the share solely from a shell, you will need an additional package.

Accessing a Samba Share from Gnome

From a Nautilus window, hit Template:Keypress+Template:Keypress or go to the "Go" menu and select "Location..." - both actions will allow you to type in the "Go to:" blank. Enter smb://servername/share followed by the Template:Keypress.

Note: If you do not have your servername in your Template:Filename, you must use the IP Address of the server in place of the servername.
smb://servername/sharename

or

smb://192.168.1.5/sharename

A variant of the above should also work in KDE.

Accessing a Samba Share from the Shell

You can also use smbclient to browse shares from the shell.

$ smbclient -L <hostname> -U%

Will list any public shares on the server.

For a GUI in the KDE SystemSettings you have to install the kdenetwork-filesharing package from Extra.

Mounting a Samba Share

To manually mount a share from the shell:

# mount.cifs //<hostname>/<share> <mount_point> -o user=<username>,password=<password>

To allow a normal user to mount and unmount a Samba share you can add setuid root to /sbin/mount.cifs. An alternative is to use the smbnetfs package.

Adding a Share to fstab

You can add a line to fstab like this:

//<hostname>/<share> <mount_point> cifs credentials=<credentials_file>,rw,user,noauto 0 0

Since fstab is readable by all users, we don't want to put our Samba password in this file. In this case we can use a credentials file that is only readable by you. This is a simple text file that contains:

username=<username>
password=<password>

The user option of the fstab line allows the owner of the <mount_point> to mount and unmount the share. The noauto option disables mounting at boot.

If you are adding a Samba share to fstab, you should also add the netfs daemon to rc.conf, somewhere after the network daemon. The netfs daemon will mount network partitions at boot and, more importantly, unmount network partitions at shutdown. Even if you are using the noauto option in fstab you should add the netfs daemon. Without it any network share that is mounted when you shutdown will cause the network daemon to wait for the connection to time out, consideribly extending your shutdown time.

Share files for your LAN without user and password

Edit default /etc/samba/smb.conf on the following lines:

security = user

to

security = share

If you want to restrict the shares data to a specific interface replace

;   interfaces = 192.168.12.2/24 192.168.13.2/24

to (replace eth0 to local network you want share to)

interfaces = lo eth0
bind interfaces only = true

if you want to edit the account that access the shares, edit the following line:

;   guest account = nobody

The last step is to create share directory (for write access make writable = yes):

[Public Share]
path = /path/to/public/share
available = yes
browsable = yes
public = yes
writable = no

Sample configuration file

The configuration that worked for me:

[global]
workgroup = WORKGROUP
server string = Samba Server
netbios name = PC_NAME
security = share
; the line below is important! If you have permission issues make sure the user here is the same as the user of the folder you want to share
guest account = mark
username map = /etc/samba/smbusers
name resolve order = hosts wins bcast
wins support = no
[public] comment = Public Share path = /path/to/public/share available = yes browsable = yes public = yes writable = no

Troubleshooting

If you are having trouble accessing a password protected share from Windows, try adding this to the /etc/samba/smb.conf Suggestion found here

[global]
# THE LANMAN FIX
client lanman auth = yes
client ntlmv2 auth = no

See Also

More Resources