Setting up a simple Samba Share - sakaki-/gentoo-on-rpi-64bit GitHub Wiki
This example is for a basic shared drive that can be accessed from windows without a username / password.
Just to move files back and forth in an easy fashion.
A more detailed setup can be gleaned from reading the gentoo wiki guides.
First lets make sure the packages we need are installed
emerge net-fs/samba
emerge cifs-utils
Next setup a new configuration
cp /etc/samba/smb.conf.default /etc/samba/smb.conf
Setup a new directory for general sharing (the below is just an example)
mkdir /mnt/vol2/share
chown -R demouser /mnt/vol2/share
chgrp -R demouser /mnt/vol2/share
Add a password for demouser
:
smbpasswd -a demouser
Next lets change some settings
# Default workgroup used by most windows installs
workgroup = WORKGROUP
# Our server identity
server string = pi64 server
netbios name = PI64
# Lets add all interfaces
interfaces = wlan0 lo eth0
# Lets add in our local subnet (this will vary based on your internal network in use)
# The 127. is for local loopback on 127.0.0.1
hosts allow = 192.168.1. 127.
# Deny everything else
hosts deny = 0.0.0.0/0
# Misc
wins support = Yes
passdb backend = smbpasswd
# This compares the user trying to access the share to the samba database
# if no match is found then map to the guest user account, this allows for shares with no logons
security = user
map to guest = Bad User
# Setup a directory anyone can read / write from
# but writes will appear to originate from the demouser account
[share]
path = /mnt/vol2/share
public = yes
only guest = yes
writable = yes
printable = no
force user = demouser
# To start the service up
/etc/init.d/samba start
# To add samba to the default run level
rc-update add samba default
You may also want to start and enable the avahi
daemons (optional) as samba
now ships with the zeroconf
USE flag set:
rc-service avahi-daemon start
rc-service avahi-dnsconfd start
rc-update add avahi-daemon default
rc-update add avahi-dnsconfd default
In order to access the share from windows try typing in the following into windows explorer
\\<server-name>\
\\<server-name>\share
Lets say we want to mount from within linux (a different linux box)
mkdir -p /mnt/test
mount.cifs //<server-name>/share /mnt/test -o guest
If we want to add to fstab to mount on bootup
//<server-name>/share /mnt/test cifs guest
In addition to sharing directories explicitly via /etc/samba/smb.conf
, you can also use a provided plugin to allow sharing by users directly from the standard thunar
file browser.
To install the tool:
pi64 ~ # emerge thunar-shares-plugin
An administrative directory is required; create this now with the appropriate permissions:
pi64 ~ # mkdir -pv /var/lib/samba/usershares
pi64 ~ # chown root:adm /var/lib/samba/usershares
pi64 ~ # chmod 1770 /var/lib/samba/usershares
Add the following (adapt as appropriate) to the [global]
section of /etc/samba/smb.conf
(replacing the current security = user
line):
####### Authentication #######
security = user
usershare path = /var/lib/samba/usershares
usershare max shares = 100
usershare allow guests = yes
usershare owner only = yes
Now restart samba
:
pi64 ~ # rc-service samba restart
As a regular user, you should now find you can right-click on a folder, select Properties
from the dropdown, and then share the folder using the Sharing
tab of the properties dialog.
As the SMB1
protocol is now deprecated (and disabled on Windows 10 by default, unless used shortly after initial bring-up) another mechanism is required to allow samba
hosts (such as your RPi) to be found by modern Windows PCs. Fortunately a Web Services Discovery daemon is available for this purpose. To install it, issue:
pi64 ~ # emaint sync --repo genpi64
pi64 ~ # emerge net-misc/wsdd
Start the daemon, and have it come up automatically on boot:
pi64 ~ # rc-service wsdd start
pi64 ~ # rc-update add wsdd default
That's it! Your Pi should now be visible even to Windows 10 machines on your local network.
Unfortunately, SMB1
is also used by file browsers such as thunar
to allow browsing of the local Windows network. As samba
/ gvss
has now migrated to a more modern version of the SMB protcol, nothing will now show up when you click Browse Network
-> Windows Network
.
It is possible to force the use of SMB1
by placing the following in the [global]
section of /etc/samba/smb.conf
:
client max protocol = NT1
however as this will cause all files to be transferred using the less-secure SMB1
protocol also, doing so is not recommended.
You can still connect to a Windows host in the default configuration, but you need to know its name or IP address on the local subnet; just enter
smb://<address>
into the thunar file browser.