sudo apt-get update
sudo apt-get install samba samba-common-bin
Set Samba password
sudo smbpasswd -a pi
sudo smbpasswd -a guestuser # or whoever
Create a copy of config file
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Edit smb.conf
sudo nano /etc/samba/smb.conf
Add the following to the bottom
# Note the brackets around the folder name
[yourfoldername]
comment = Some Label
path = /path/to/share/folder
valid users = pi,guestuser
read only = no
If you're looking to share your external drive connected to your pi, follow the instructions at the end
and replace path =
above or add a new entry with path = /path/to/externalmountpoint
So for example, we mounted our external drive as /media/external
using the instructions at the end, our new/updated entry would be:
# Note the brackets around the folder name
[extrastorage]
comment = Some Label
path = /media/external
valid users = pi,guestuser
read only = no
Now our external usb/drive connected to our pi would be available to our computer under the Samba folder extrastorage
(once its all connected)
Test nothings wrong
testparm
Restart Samba
sudo service samba restart
or
sudo systemctl start(or restart) smbd
See if you can connect to the Samba Server
smbclient -L localhost
If smblcient is not found, as on Jessie it wasn't, also do:
sudo apt-get install smbclient
Samba server is running :)
For one time mount (possibly to test)
# yourfoldername is the folder you placed inside the [] in the smb.conf
# Will probably need to supply the password
sudo mount //ipaddressofpi/yourfoldername /media/mymountpoint
To mount Samba folders on linux boot up
- Example below will use the example samba user pi
Enter credentials for pi user and place into /etc/samba/pi
sudo touch /etc/samba/pi
sudo nano /etc/samba/pi
Place the following in the file:
username=pi
password=yoursambapassword
Create backup of fstab
sudo cp /etc/fstab /etc/fstab.bak
sudo nano /etc/fstab
Add following to bottom
//ipaddressofpi/yourfoldername /media/mymountpoint cifs credentials=/etc/samba/pi,user,nofail 0 0
To view the home folder for the SMB user use /homes
otherwise use the foldername you entered into the smb.conf (or create a seperate entry for both)
Now as long as the samba server is running, you'll see the folder in your file manager
At the top of your mac (no programs selected) Go > Connect to server.
Enter the ipaddress of the pi
smb://ipaddressofpi
Click connect
Enter your SAMBA credentials (not the pi credentials)
Done
This is all theoretical, as I have not tested this as of yet
Open file explorer
Click Network (on the side) or if you see Map Network Drive anywhere, click it
Select unselected drive letter and enter:
\\raspberrypi\yoursambausername
Click the Connect Using Different Credentials
Enter your SAMBA credentials (not your pi credentials)
Done
This tutorial assumes a usb, but if your pi powers your harddrive, same principles apply
First check to see if the pi is reading your external drive/usb
sudo fdisk -l
Sample output
Disk /dev/mmcblk0: 7860 MB, 7860125696 bytes
4 heads, 16 sectors/track, 239872 cylinders, total 15351808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a109
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 1685546 838677+ e W95 FAT16 (LBA)
/dev/mmcblk0p2 1687552 15286271 6799360 85 Linux extended
/dev/mmcblk0p3 15286272 15351807 32768 83 Linux
/dev/mmcblk0p5 1695744 1818623 61440 c W95 FAT32 (LBA)
/dev/mmcblk0p6 1826816 15286271 6729728 83 Linux
Disk /dev/sda: 3875 MB, 3875536896 bytes
86 heads, 22 sectors/track, 4000 cylinders, total 7569408 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4a089361
Device Boot Start End Blocks Id System
/dev/sda1 8064 7569407 3780672 c W95 FAT32 (LBA)
If you don't see a /dev/sda1 or /dev/sdb1 etc, and its an external harddrive, it means your current configuration of the pi does not power your external harddrive.
- 2 Options
- 1: Get a powered usb hub
- 2: Follow instructions here (with caution) on attempting to power the HDD with the pi https://www.reddit.com/r/raspberry_pi/comments/44si1j/using_a_raspberry_pi_and_an_external_hd_for/
If you see /dev/sdaX1 (Where X is a, b,c etc) - proceed
Backup fstab
sudo cp /etc/fstab /etc/fstab.bak
Edit the fstab file and add the following to the bottom, where X is the letter from fdisk -l
sudo nano /etc/fstab
# Note: fdisk will tell you the filesystem type of your external
# If you plan on having multiple externals with different file systems, thats beyond
# the scope of this gist/tutorial
# For fat32 file systems, use vfat
/dev/sdX1 /media/mymountpoint vfat defaults 0 0
Now on pi bootupt (with usb/drive plugged in) files will be available at /media/mymountpoint
Without restarting (or you plugged the usb/drive in AFTER bootup) mount -a