The {{ic|noauto}} option disables mounting it automatically at boot and {{ic|noatime}} increases performance by skipping inode access times. However, the {{ic|noatime}} is known to cause mount [https://bbs.archlinux.org/viewtopic.php?pid=1117000 problems] with kernel 3.4.x:

+

The {{ic|noauto}} option disables mounting it automatically at boot and

−

+

−

# mount error(22): Invalid argument

+

−

# Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

+

After adding the previous line, the syntax to mount files becomes simpler:

After adding the previous line, the syntax to mount files becomes simpler:

Revision as of 22:09, 10 December 2012

Samba is a re-implementation of the SMB/CIFS networking protocol, it facilitates file and printer sharing among Linux and Windows systems as an alternative to NFS. Some users say that Samba is easily configured and that operation is very straight-forward. However, many new users run into problems with its complexity and non-intuitive mechanism. It is strongly suggested that the user stick close to the following directions.

Configuration

Basic Setup

The /etc/samba/smb.conf file must be created before starting the daemons. Once that is set up, users may opt for using an advanced configuration interface like SWAT.

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

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

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

More information about the options available can be found in man smb.conf. Here is the online version.

To make samba work, start samba daemon or make it automatically start at boot.

Classic init

# rc.d start samba

Systemd

# systemctl start smbd.service nmbd.service

Note: After starting the samba daemon check that files smbd.pid and nmbd.pid exist in /var/run/samba/ otherwise you will get an error. If not, simply create /var/run/samba directory and restart samba daemon.

Web Based Option

SWAT: Samba web administration tool

SWAT is a facility that is part of the Samba suite. The main executable is called swat and is invoked by the eXtended InterNET Daemon, xinetd.

There are many and varied opinions regarding the usefulness of SWAT. No matter how hard one tries to produce the perfect configuration tool, it remains an object of personal taste. SWAT is a tool that allows Web-based configuration of Samba. It has a wizard that may help to get Samba configured quickly, it has context-sensitive help on each smb.conf parameter, it provides for monitoring of current state of connection information, and it allows network-wide MS Windows network password management.[1]

Note: An all-encompasing Webmin tool instead can also be used, and easily load the SWAT module there.

Warning: Before using SWAT, be warned that SWAT will completely replace smb.conf with a fully optimized file that has been stripped of all comments , and only non-default settings will be written to the file.

Accessing shares

Shared resources from other computers on the LAN may be accessed and mounted locally by GUI or CLI methods The graphical manner is limited. Some Desktop Environments have a way to facilitate accessing these shared resources. However, most do not. In fact, most lightweight DE's and WM's offer no native method.

There are two parts to share access. First is the underlying file system mechanism, and second is the interface which allows the user to select to mount shared resources. Some environments have the first part built into them.

If using KDE, it has the ability to browse Samba shares. Therefore do not need any additional packages. (However, for a GUI in the KDE System Settings, install the kdenetwork-filesharing package from [extra]. Another program choice is SMB4K.) If, however, users wish to use the share in Gnome or solely from a shell, an additional package is needed.

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

Note: If the servername is not in /etc/hosts, use the IP address of the server in place of the servername.

From a Pcmanfm window, under the "Go" menu choose "Network Files".

Another GNOME browser program is Gnomba.

If iptables is running, the nf_conntrack_netbios_ns module should be loaded:

modprobe nf_conntrack_netbios_ns

Accessing shares from other graphical environments

There are a number of useful programs, but they will need to have packages created for them. This can be done with the Arch package build system. The good thing about these others is that they do not require a particular environment to be installed to support them, and so they bring along less baggage.

LinNeighborhood is non-specific when it comes to the DE or WM. It can be seen as a simple and generic X-based LAN browser and share mounter. Not pretty, but effective.

Other possible programs include pyneighborhood and RUmba, as well as the xffm-samba plugin for Xffm.

Accessing a Samba share from the shell

Shares may be accessed by using an automatic mounter or by using a manual method.

The IP address of the server -- if the system is unable to find the Windows computer by name (DNS, WINS, hosts entry, etc.)

Note: Abstain from using trailing directory (/) characters. Using //SERVER/SHARENAME/ will not work.

As CIFS refuses to mount unsecured samba share, the sec=none option needs to be used (and the user and password from the options list need to be removed).

If the mount command cannot resolve the server’s address but smbclient can, adding wins to the hosts line in /etc/nsswitch.conf may help. The corresponding /lib/libnss_wins.so driver must also be present, which is provided by the samba (server) package.

It is highly recommended to chmod 600 this file so that only the owning user can read and write to it.

If adding a Samba share to fstab, the netfs daemon should also be added 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 using the noauto option in fstab, the netfs daemon should be used. Without it any network share that is mounted when shutting down will cause the network daemon to wait for the connection to time out, considerably extending poweroff time.

Allowing users to mount

Before enabling access to the mount commands, fstab needs to be modified. Add the users options to the entry in /etc/fstab:

Note: The option is users (plural). For other filesystem types handled by mount, this option is usually user; sans the "s".

This will allow users to mount it aslong as the mount point resides in a directory controllable by the user; i.e. the user's home. For users to be allowed to mount and unmount the Samba shares with mount points that they do not own, use #smbnetfs, or grant privileges using sudo.

Tips and tricks

Share files without a username and password

Edit /etc/samba/smb.conf and add the following line:

map to guest = Bad User

After this line

security = user

Restrict the shares data to a specific interface replace:

; interfaces = 192.168.12.2/24 192.168.13.2/24

with:

interfaces = lo eth0
bind interfaces only = true

Optionally 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):

Sample configuration file

[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

Adding network shares using KDE4 GUI

How to configure the folder sharing in KDE4. Simple file sharing limits user shared folders to their home directory and read-only access. Advanced file sharing gives full semantics of Samba with no limits to shared folders but requires su or sudo root permissions.

This shows which folders are shared and can be mounted locally. See: #Accessing shares

Remote control of Windows computer

Samba offers a set of tools for communication with Windows. These can be handy if access to a Windows computer through remote desktop is not an option, as shown by some examples.

Send shutdown command with a comment:

$ net rpc shutdown -C "comment" -I IPADDRESS -U USERNAME%PASSWORD

A forced shutdown instead can be invoked by changing -C with comment to a single -f. For a restart, only add -r, followed by a -C or -f.

Stop and start services:

$ net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD

To see all possible net rpc command:

$ net rpc

Block certain file extensions on samba share

Samba offers an option to block files with certain patterns, like file extensions. This option can be used to prevent dissemination of viruses or to disuade users from wasting space with certain files:

Troubleshooting

A known Windows 7 bug that causes "mount error(12): cannot allocate memory" on an otherwise perfect cifs share on the Linux end can be fixed by setting a few registry keys on the Windows box as follows:

Only the sleep 5 line is inserted, everything else is as from the Arch repositories.
It causes a delay of 5 seconds before starting the samba server. In order to avoid the additional boot-time, start the Samba daemon in background, as described above.

The file /etc/rc.d/samba is part of the samba package, though. Therefore, manually apply this change every time Samba gets updated.

Sharing a folder fails

If sharing a folder from Dolphin (file manager) and everything seems ok at first, but after restarting Dolphin (file manager) the share icon is gone from the shared folder, and also some output like this in terminal (Konsole) output: