Link to home
Start Free TrialLog in
Avatar of KzKrew
KzKrewFlag for United States of America

asked on

Linux Samba Share on Raspberry Pi

I am attempting to write a text file using python to a Samba Share on a Raspberry Pi - OS Raspberry PI OS.  have setup the smb.config file as shown

  comment=TestPage
 path=/home/pi/share/testpage
 browseable=Yes
 writeable=Yes
 guest ok = yes
 create mask=0777
 directory mask=0777
 public=yes
I think i could get rid of the 0777 mask but its working fine as is for anonymous access for windows users.  But cannot get to work for other Raspberry pi systems

"Access Denied" 

Have updated fstab with the multiple variations of the following


//10.1.80.26/share/testpage   /home/pi/share/pageshare 


Looking to the Experts for tried true working command that i should be using 

Thanks  - Dan

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Which of the 2 masks is it that you want to get rid of and why is that? Also what do you mean by 'working fine' - can you explain, is writing to the share working from other applications?

I'm using a similar setup and have used the same on a Raspberry - the way I set it up back then is written down in this article: https://www.experts-exchange.com/articles/19239/Simple-NAS-with-a-Raspberry-PI.html I'm connecting with a username and password 
Avatar of KzKrew

ASKER

Working fine means that i can drop a file into or write a file to the samba public share with no issues from a Windows machine. I only made reference to the 2 Masks based on reading some articles hinting the Masks were moot when using public anonymous share.
To reemphasize my question:
I have setup a samba anonymous public  share on one Raspberry Pi using the following Samba Config

  comment=TestPage
 path=/home/pi/share/testpage
 browsable=Yes
 writeable=Yes
 guest ok = yes
 create mask=0777
 directory mask=0777
 public=yes

I would like to be able to write files to this share from both Windows and other Linux based Raspberry Pi systems.
Currently i am only able to write to the share from Windows machines.
I get an Access denied error when attempting to write to the share using a Linux based Raspbeery Pi with latest Raspberry Pi OS. The reason for needing anonymous access is that i have hooks into Industrial Controller OPC services that do not support UserName/Passwords. I have no issues writing from those OPC services.
My question to the Experts
What should my mount config look like write files to //10.1.80.26/share/testpage

Thanks - Dan

Avatar of KzKrew

ASKER

Can one of the experts weigh in on this. I have tried multiple fstab integrations
//10.1.80.26/share/testpage   /home/pi/share/pageshare cifs guest,_netdev 0 0
and many more. 
Need Assistance
Thanks 
1) Best to start with 64 Bit everything on all Pi devices.

2) If all Pis live on 10.1.80.X then all should be well. Any other networks will likely require a manual route.

3) Useful test will be to ping 10.1.80.26 from one of your other failing Pis.

4) Also if there are any firewall rules running on any Pis, purge all rules (iptables -F) then retest, as if you're running a firewall on any Pi this might be the problem source.
Avatar of KzKrew

ASKER

64 Bit may be an option in the future but not now
All Pis live on same network. NO problem pinging one another. Working in test environment with no routing or firewalls in place. In the RPI OS Gui i can go to Folders Explore - then Go Then network and double click on my share and able to connect and write to share with no problems

Could the  Experts help me out with how my  fstab config should look like for a anonymous
 
Dan

Avatar of noci
noci

1) did you create a /home/pi/share/Testpage   (empty) directory ?
2) the mount probably should be:    mount -t cifs //10.1.80.26/TestPage  /home/pi/share/Testpage    
(+ options etc...)
And thus added to /etc/fstab:     //10.1.80.26/TestPage  /home/pi/share/Testpage  cifs defaults 0 0  
(+ other options if needed)
Avatar of KzKrew

ASKER

noci
I have changed things up a bit from original question description -- moved to a sandbox network
your config
//192.168.0.99/frfpage /home/pi/share/frfpage cifs defaults 0 0  
prompts for a password when i attempt to mount -- sudo mount /home/pi/share/frfpage
But does mount and i can access the share but cannot write to it
I then changed things up a bit more -- added file and dir mode -- this now works to write to share but is prompting for password when attempting to mount  -- can you assist in how i should enter password into fstab
//192.168.0.99/frfpage /home/pi/share/frfpage cifs file_mode=0777,dir_mode=0777
Avatar of KzKrew

ASKER

I have tried to include the password into the fsab config as shown but then get the following error when trying to mount
//192.168.0.99/frfpage /home/pi/share/frfpage cifs username=root password=admin file_mode=0777,dir_mode=0777
User generated image
I think this article escribes all your options...
https://help.ubuntu.com/community/MountCifsFstab

username & password are just extra options..., be advised /etc/fstab can be read by everyone.
options should be entered as ONE word without spaces, using , (comma's) as separator.
username=xxx,password=yyyy,file_mode=0777,...

Also when using RPi as storage device ENSURE you use an USB stick/disk as storage. SD cards are not very good to be  continuously rewriten, they wil fail rather quickly on the home block writes.  USB devices usuably employ wear leveling  (better check that by the way).

I tested the mount interactively, it's working as @noci is describing. Note that I have a share setup where I noticed Windows does not ask for a password where the Raspberry does require this.

This is my fstab entry:
//192.168.xxx.yyy/shared /tmp/test cifs defaults 0 0

This is how I mounted:
mount -t cifs //192.168.xxx.yyy/shared /tmp/test -o user=zzz
(password prompt, entered the user password)

After that I could write to /tmp/test from the Raspberry to create files on the share (other Raspberry).
@Gerwin, if there were valid credentials from the past, they may have been cached. Or if the required credentials are the same as from the logged on user.
@Noci - I did verify that in Credential Manager in Windows - nothing there, this is where you would expect to find saved passwords. After a reboot of the Windows machine access to the shared folder still works without username/password - they are not the same as on the Raspberry share...
Avatar of KzKrew

ASKER

Thanks Team Experts -- will give it a try and let you know 
Avatar of KzKrew

ASKER

Gerwin / Noci
I am really stumped with this one. I believe I have setup things per your recommendation but still getting the access denied.
I am now in the process of creating clean installs for both Pi’s and configure per your instructions.
Could you provide a step by step instruction for me to follow how you were able to get clear of the Access Denied error

“After that I could write to /tmp/test from the Raspberry to create files on the share (other Raspberry)”

Thanks - Dan
Avatar of KzKrew

ASKER

Gerwin / Noci == this is the process i followed 
File Share Pi
Run updates
Create Shard Folder
mkdir tmp
mkdir tmp/test
Set folder permissions
                chmod 777 /home/pi/tmp/test
 
Install Samba                     sudo apt-get install samba samba-common-bin
 
Update smb.config          sudo nano /etc/samba/smb.conf
Verify the following
workgroup = WORKGROUP
wins support = yes
Add the following at end of file
[PiShare]
 comment=Raspberry Pi Share
 path=/home/pi/tmp/test
 browseable=Yes
 writeable=Yes
 only guest=no
 create mask=0777
 directory mask=0777
 public=yes
 
Set Samba password       sudo smbpasswd -a pi
Save and reboot
Test on windows – can write to shared folder
 
Client Pi 
Run updates
Create mount folder
mkdir tmp
mkdir  tmp/test
 
Update fstab entry          sudo nano /etc/fstab
 
                //192.168.1.159/shared /tmp/test cifs defaults 0 0
 
Mount
                sudo mount -t cifs //192.168.1.159/PiShare /tmp/test -o user=pi

Same issue -- what am i doing wrong
User generated image
maybe this helps a littlebit:
Given the next command:
mount -t ${FSTYPE}  ${DEVICE} ${MOUNTPOINT} -o ${OPTIONS}

in FSTAB al data is in one row:
DEVICE    MOUNTPOINT    FSTYPE  OPTIONS  DUMP PASS

All fields are Blank (=space or tab) separated, ==> no spaces INSIDE a field, all options should be in a single field, without space/tabs.
in your case FSTYPE = cifs   the DEVICE is the Path to the share (using forward-slash / not back-slash \
MOUNTPOINT path to a local empty directory on the local system which provides a portal the other filesystem.

DUMP is an options for automated sheduled backups using the dump utility.

PASS is the order during bootup so nested mounts can be done.  /  is premounted    0 is done first, 1 is next, 2 then etc.
for example
........  /var ......... 1
........ /var/log .......  2
Allows you to mount a /var/log after mounting /var.

You may need to increment the last 0 on your line to first allow /tmp to be mounted.
After mounting a networked filesystem (in your case on /tmp/test ) ALL access to /tmp/test and below are done accoring to the rules of the filesystem mounted there.
therefore  it is done on a remote filesystem,
Avatar of KzKrew

ASKER

Thanks noci -- that helps clarify things a bit. But after 5 hours of starting from scratch along with different configs -- still running into same access denied issue. Could you or Gerwin profide a step by step process that enabled rw on the second pi in your testing?
Thanks - Dan


I have no spare RPi atm... for some reason a delivery of two i ordered in november is still in delivery.That said it jus "only"-linux...

Given that your share is called PiShare do you use

mount -t cifs //RPiServer/PiShare /tmp/test -o ......

Als can you show some of your log data: (server side)
/var/log/samba/*.log    (check which one is used)

The CIFS client (kernel driver)  sends output to the kernel log (viewable with dmesg, or in /var/log/kernel.log )
I'll give you an overview of the config files I have later today. Not at a computer atm

But from what I read above you are specifying a different mount point than the one I am using. yours is under your home directory where mine is under /tmp - can you check the mount point etc fstab and the share location are OK?
Avatar of KzKrew

ASKER

Gerwin -- i changed things up a bit to match your config
fstab
//192.168.1.57/shared /tmp/test cifs defaults 0 0

mount  - if i try to mount without sudo  using the following --mount.cifs: permission denied as shown
pi@raspberrypi:~ $ mount -t cifs //192.168.1.57/shared /tmp/test -o user=pi
mount.cifs: permission deni
ed

then mount with sudo
pi@raspberrypi:~ $ sudo mount -t cifs //192.168.1.57/shared /tmp/test -o user=pi
Password for pi@//192.168.1.57/shared:
ok have mounted folder now
when i try to write - get permission denied

pi@raspberrypi:/tmp/test $ touch testfile.txt
touch: cannot touch 'testfile.txt': Permission denied
pi@raspberrypi:/tmp/test $

then try with sudo 
pi@raspberrypi:/tmp/test $ sudo touch testfile.txt
File is then created on the Share

I gues its not the worst thing in the world to have to use sudo to write to file -- at least its somewhat working
Still need to figure out how to figure out fstab to automount on reboot.
Dan
So on the Raspberry Pi Server the share is named share.   (And not PiShare  ass shown before)
The smb.conf file contains section

...
[share]
 comment=Raspberry Pi Share
 path=/home/pi/tmp/test
 browseable=Yes
 writeable=Yes
 only guest=no
 create mask=0777
 directory mask=0777
 public=yes
...

Open in new window

The mount is working - that is good news! Ik just looks like you have a file permission issue, we should be able to fix that.

Can you show the output of "ls -l /tmp/test" after mounting the share?

This is the /etc/fstab entry I have now:
//192.168.xxx.yyy/shared /home/pi/test cifs credentials=/home/pi/creds,uid=1000,gid=1000 0 0

I created a credentials file ~/creds that has 2 lines:
username=xxx
password=yyy

Key thing to get write access is that you add uid/gui to the fstab entry, I have 1000 and 1000 for id and guid of the pi user - you will probably have the same.

When I got it working earlier - I was probably logged on as root - that's why the write was working for me. I tried again like you did and got the same access denied. After adding the uid and guid that's what got it fixed for me.

pi@raspberry:~ $ ls -ld test
drwxr-xr-x 2 pi pi 0 Mar 14 00:14 test
Avatar of KzKrew

ASKER

Thanks all -- see below for  "ls -l /tmp/test" after mounting
pi@raspberrypi:/tmp/test $ pi@raspberrypi:/tmp/test $ ls -l /tmp/test
total 0
-rwxr-xr-x 1 root root 0 Mar 13 14:41 'New Text Document.txt'
-rwxr-xr-x 1 root root 0 Mar 13 17:10  testfile.txt
-rwxr-xr-x 1 root root 0 Mar 13 15:00  text112.txt
pi@raspberrypi:/tmp/test $

Thanks to the experts for bringing this together. Have really learned a lot - so cool
I will update fstab in am and try out.

Your statement
Key thing to get write access is that you add uid/gui to the fstab entry, I have 1000 and 1000 for id and guid of the pi user - you will probably have the same.
How would i find that out

I did have one other item that may be resolved with creds file. That is that upon reboot the mount was lost???
Let me know
Again -- thanks a ton
Dan
You use the id command to find the uid/guid for a user, like this:

id pi

You will get a list where the group is shown with a number as well as the user. You could see multiple groups in the list. 
Avatar of KzKrew

ASKER

Gerwin
I did verify uuid of pi user uid=1000(pi) gid=1000(pi)
Created creds file and placed in /home/pi
Updated fstab    sudo nano /etc/fstab
//192.168.0.99/shared /home/pi/test cifs credentials=/home/pi/creds,uid=1000,gid=1000 0 0
Attempted to run mount command but it appears its not picking up credentials file -- prompts for password

pi@FRF-TR-20-1:~ $ sudo mount -t cifs //192.168.0.99/shared /tmp/test
Password for root@//192.168.0.99/shared:  *******
pi@FRF-TR-20-1:~ $

Checked mount – able to write using sudo
pi@FRF-TR-20-1:~ $ cd /tmp/test
pi@FRF-TR-20-1:/tmp/test $ touch testfile
touch: cannot touch 'testfile': Permission denied
pi@FRF-TR-20-1:/tmp/test $ sudo touch testfile
pi@FRF-TR-20-1:/tmp/test $

pi@FRF-TR-20-1:/ $ ls -ld /tmp/test
drwxr-xr-x 2 root root 0 Mar 14 10:40 /tmp/test
pi@FRF-TR-20-1:/ $

Let me know Dan


The credential file MUST be accesible during mounts (early in boot) so better place it in f.e. /etc/samba  or another place in /etc.. (you can create your
own directory like: /etc/credentials/... 
Avatar of KzKrew

ASKER

Thansk noci  -- i did read that someplace on the creds file location. Have also set pi to hold boot until network is up
Recreated creds file and placed per your rec
Updated fstab
//192.168.0.99/shared /home/pi/test cifs credentials=/etc/credentials/creds,uid=1000,gid=1000 0 0
saved and rebooted -- still not picking up fstab on boot
Mounted manually
pi@FRF-TR-20-1:~ $ sudo mount -t cifs //192.168.0.99/shared /home/pi/test
Password for root@//192.168.0.99/shared:  *******
pi@FRF-TR-20-1:~ $

Still appears that it is not picking up creds file -- do i need to change my mount command?
Dan



First does the cred file work on a manual mount?
Anything in any of the log files?   (most probably kernel log, or through the dmesg command )
Mostly tools are quite informative when errors occur.

Avatar of KzKrew

ASKER

I do not think the cred file is being called properly in fstab.
I have changed the cred file name in the fstab and it does not error(i.e cant find credentials file)
That said -- i can mount manually but its prompting for password
pi@FRF-TR-20-1:~ $ sudo mount -t cifs //192.168.0.99/shared /home/pi/test
Password for root@//192.168.0.99/shared:  *******
pi@FRF-TR-20-1:~ $ 
You test the creds file by using the right options on the mount command...

sudo mount -t cifs //192.168.0.99/shared /home/pi/test -o credentials=/etc/credentials/creds,uid=1000,gid=1000

It should not give errors and not ask for username/password.

ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KzKrew

ASKER

noci / Gerwin
Cant thank you two enough - works like a charm.
I think my problem was tied to how i was attempting to mount with fstab -- mixing configs between the fstab and mount commands
Will follow up with personal message to explain more in the am