23

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?

goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
asked Jan 12, 2016 at 11:25
5
  • 1
    ftp would be much faster Commented Jan 12, 2016 at 11:51
  • 1
    Yes I know, but It's tedious to install FTP server on all of my Windows PC's Commented Jan 12, 2016 at 11:53
  • 3
    You want a samba client. I am sure you will find many explanations of such online if you search "linux samba client", although of course some of them will actually be about about using a client to access a share on a linux box rather than the other way around. I believe the CLI utility for this is smbclient. Commented Jan 12, 2016 at 11:57
  • @goldilocks Thanks, but Is there any workaround for the default File Manager to open Samba? :) Commented Jan 12, 2016 at 12:08
  • 1
    The file manager in LXDE (the default desktop environment on Raspbian) is "pacmanfm", so if you search for "pacmanfm samba" you should find a bunch of stuff, e.g., askubuntu.com/q/249678/239729 I suggest for samba-on-linux stuff generally you start on U&L. Commented Jan 13, 2016 at 12:51

6 Answers 6

30

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
answered Jan 13, 2016 at 22:08
4
  • +1 This has worked for a shared USB drive connect to the USB port of a Modem/Router. If you need some more debugging add '--verbose' before the '-o' Commented Sep 23, 2016 at 3:39
  • I have this error with my credentials : Device or resource busy. Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) Commented Oct 21, 2017 at 11:10
  • I have to look up how to do this every time. This answer is very clear and concise. Thanks :) Commented Feb 5, 2019 at 19:10
  • 1
    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
12

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.

goldilocks
60.4k17 gold badges117 silver badges236 bronze badges
answered Jun 30, 2018 at 14:47
1
  • I'm just a noob but FWIW, man mount specifies Note that it is a bad practice to use mount -a for fstab checking. The recommended solution is findmnt --verify. Commented Sep 27, 2023 at 4:24
4

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.

Greenonline
2,9725 gold badges27 silver badges38 bronze badges
answered Oct 15, 2018 at 7:30
2
  • vers=1.0 also solved the problem for me. sudo mount -t cifs //[remote ip address]/downloads /mnt/abc -o vers=1.0,user=[user] Commented Oct 28, 2018 at 15:01
  • Using vers=1.0 work for me, too, sudo mount -o vers=1.0 //[NAS_IP]/nas /media/pi/nas Commented Jul 24, 2019 at 13:21
0

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:

  1. Retrieve your SD card from the Pi and using a adapter mount the card to your PC, Mac or Linux.
  2. You should be able to see the /boot partition of your SD card.
  3. Locate the file cmdline.txt and add the following at the end of the line init=/bin/sh Note: Do not create a new line, just add the above to end of the current line.
  4. Load the SD card back to your Pi and boot up.
  5. 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.
  6. 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 to mmcblk0p1 & mmcblk0p2. The second device mmcblk0p2 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.

answered Dec 8, 2018 at 18:32
0

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

answered Jul 25, 2021 at 16:32
0

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

answered Aug 2, 2021 at 2:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.