Here is my workflow and the issues I want to fix.

First I mount the windows shared folder on Raspberry Pi. But in order to use that, I have to mount using sudo.

sudo mount.cifs //<hostname or IP address>/share /home/pi/windowshare -o user=<name>

Once I run ls -l, the folder is in root access.

drwxr-xr-x  2 root root        0 Oct 19  2022  windowshare

This is my (test.py) python program.

import cv2
img = cv2.imread("/home/pi/Pictures/Test.jpeg")
path = '/home/pi/windowshare'
name = '/test_img.jpg'

I just want to save the image to the mount folder. But once I run my python program, it raises the error.

[ WARN:0] global /home/pi/opencv/modules/imgcodecs/src/loadsave.cpp (771) imwrite_ imwrite_('/home/pi/windowshare/test_img.jpg'): can't open file for writing: permission denied

But it works if I run sudo python3 test.py.

So I have used sudo chmod -R 755 /home/pi/windowshare but it doesn't work.

I want to run the program without using sudo. Could anyone pls help me suggest to solve this issue?

  • sudo chown pi pi
    – SBF
    Commented Oct 19, 2022 at 8:31

1 Answer 1


Currently I am able to solve it putting uid=1000, gid=1000 in /etc/fstab automount.

In other words, I am using user account which is Pi in my case, not the root by defining UID = 1000 and GID = 1000.

  • That's a correct answer; to be a good answer, you should explain why it works... P.S. You may select your answer as the "accepted answer"; this will let readers know that this answer worked in your case.
    – Seamus
    Commented Oct 20, 2022 at 21:57
  • Yes I have put the explanation.
    – MyatKaung
    Commented Oct 27, 2022 at 2:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.