I've been using my PC to access the files on RPi, using Samba Server on RPi.
But, Is there any way I could open Samba Connections on Pi? Like browsing Windows PC Samba Files on RPi?
First install some packages:
apt-get install samba-common smbclient samba-common-bin smbclient cifs-utils
Then, create a local directory and mount the remote share:
mkdir /mnt/abc
mount -t cifs //server/share /mnt/abc
where server
is your windows computer name (dns or netbios) and share
is your windows shared directory.
Depending on the access you give to your windows share are the credentials required: if you give your share 'Everyone' read (and write) access nothing else is required, otherwise you must add credentials at mount time:
mount -t cifs //server/share /mnt/abc -o user=user,pass=password,dom=domain
replace with your own credentials.
When finished just dismount the share:
umount /mnt/abc
sudo mount -t cifs -o username=guest,password=,vers=1.0 //192.168.0.1/sda1 /home/pi/router
I had to add vers=1.0 for it to work with my routers smb share
Commented
Mar 22, 2020 at 10:53
if the samba share does not need any credentials to login and you want to mount the share when you start your raspberry pi then edit the fstab file as root
sudo nano /etc/fstab
and add the following line
//server/share /mnt/abc cifs guest 0 0
close and save the changes to the fstab file
check that everything connects as it should with
sudo mount -a
if your samba share needs a password then you you can connect use the following in your fstab entry.
//server/share /mnt/abc cifs username=username,password=password 0 0
its not the best idea to use this method if others have access to your RPi or network as fstab is readable by all and will be able to read your password.
A better solution is to use a credentials file.
nano ~/.smbcredentials
then enter your username and password into the file
username=username
password=password
save the file and change its permissions so it is not readable by others.
chmod 600 ~/.smbcredentials
then edit as root the fstab to add your samba share
//server/share /mnt/abc cifs credentials=/home/pi/.smbcredentials 0 0
again, test with
sudo mount -a
and if there are no errors then it will mount the share automatically when you reboot.
man mount
specifies Note that it is a bad practice to use mount -a for fstab checking. The recommended solution is findmnt --verify.
My issue was similar. My target was dd-wrt samba share.
My problem: unable to mount it in anyway (also fstab
from RPi3).
I had errors from "not being able to pass the password to reference to mount.cifs" to "invalid argument error 22".
I came across this post, Cannot mount samba share: Mount error (22), and this answer suggests that the solution is to add vers=1.0
to the options on mount
.
I hope that helps you.
If, after trying to auto-mount a share, you somehow run into the scenario where the Pi will no longer boot, drops you in "Emergency Mode" and/or tells you that the root account is locked, you can overcome it by following the instructions located here: Raspberry Pi Boot Issue - Root account locked!.
Summary of the linked steps for the future:
- Retrieve your SD card from the Pi and using a adapter mount the card to your PC, Mac or Linux.
- You should be able to see the
/boot
partition of your SD card.- Locate the file
cmdline.txt
and add the following at the end of the lineinit=/bin/sh
Note: Do not create a new line, just add the above to end of the current line.- Load the SD card back to your Pi and boot up.
- You should now get the a root shell prompt. From here you can undo the changes to
/etc/fstab
or whatever else that initially broke your system.- In some cases you will not be able save your changes and the system will complain of a read only file system. If you get that move to the next step.
A Raspberry Pi SD card will have two main partitions, since we cannot read the partition table directly you must manually locate the device for your root and boot partitions. You can do this by going to the
/dev
directory and you should see something similar tommcblk0p1
&mmcblk0p2
. The second devicemmcblk0p2
will be your root partition. You need to remount this with read write permissions:
mount -o remount,rw /dev/mmcblk0p2 /
This will be most easily accomplished by mounting the SD card on another computer (Mac/Linux/Windows) and editing the cmdline.txt
file there.
I had foobarred my environment with a bad fstab entry and following these instructions allowed me to unwind that error.
For me this error was solved, when it wasnt just an ip address that I specified but a folder in it.
After adding the appropriate line to fstab, I wrote this line into the terminal (with sudo). mount -t cifs -o username=USERNAME,password=PASSWORD,vers=2.1, //IP/sharedfolder /linux
I managed to do it like this. Editing the /etc/fstab file and adding the following line
//192.168.1.x/Xxx /mnt/Xxx cifs username=xx,password=xx,vers=1,0
After saving and closing I give the command mount **/mnt/Xxxx**
where it was to mount the directory. I did quick tests and it worked by passing the parameter vers, in the version 1,0 connect to DNS NAS-320L
smbclient
.