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:
mount -t cifs //server/share /mnt/abc
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:
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.
then enter your username and password into the file
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.
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 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
/bootpartition of your SD card.
- Locate the file
cmdline.txtand add the following at the end of the line
init=/bin/shNote: 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/fstabor 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
/devdirectory and you should see something similar to
mmcblk0p2. The second device
mmcblk0p2will 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.
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