Samba file server - How can I set root folder as base directory ?

Hi,

I’m new to dietpi. I installed in on my Raspberry Pi 4. It works great. But I have a question about Samba/SMB server.

I choosed Samba server over FTP for a better integration with Windows and my Windows apps. But I have an issue :

I would like the base directory to be the root folder of my pi. I often need to access various folders such as /mnt, /home … I found on the wiki how to change the base directory for the samba share, but it doesn’t work with root. I can only choose folders such as /mnt or /home as base folder. I would like to choose / . I can use this command found on the wiki :

sed -i ‘/path = /c\path = /Path/To/Directory’ /etc/samba/smb.conf
dietpi-services restart

If I only put / in /Path/To/Directory, it doesn’t work. I don’t want to enter this command each time I want to switch between /mnt or /home. I would like to be on the root of these folders in samba.

How could I do that ? Thanks in advance for any answer. Any answer is welcome. Have a good day!

H,

that should be quite easy. Just edit the smb.conf file manually.

nano /etc/samba/smb.conf
remove - path = /mnt/dietpi_userdata/
add    + path = /
systemctl restart smbd.service

see attached. That’s how it looks like :slight_smile:

1 Like

It works perfectly, thanks ! That’s exactly what I wanted to achieve.

But I have an issue : there is lots of folders I don’t have the permissions to access like /root :

How can I manage the permissions for the SMB share ? How can I authorize this folder ?

Thanks in advance for your help. Have a good day !

that’s correct because you are going to login as user dietpi but the directory is owned by user root and only root can access it

drwx------  5 root root  4096 Apr 29 15:58 root

If you really like to get access to this directory, you would need to login as user root. That would mean to allow root access to your system via SMB. Usually this is a security risk and should be avoided if possible. However it’s something that can be archived as follow:

nano /etc/samba/smb.conf
remove - valid users = dietpi
add    + valid users = root
smbpasswd -a root
systemctl restart smbd.service

The password you are going to specify is valid for SMB access only. It could be different from the OS / SSH password you are using to login to your system.

It might be Windows is caching the old SMB access (with user dietpi) and it is not going to ask for new user/password. If this happen you might need to clean your share by using net use \\dietpi /delete for example, if dietpi was still the name of your SMB share.

1 Like

Ok thanks a lot for all your help.

I use my pi to run a minecraft server, and a jellyfin media server. So the only folders I need to access through SMB are
/root/minecraft
and
/mnt

Maybe I could minimize the security risk by allowing SMB server to access only these folders (not whole /root, only /root/minecraft)
How could I do that ?

And thanks again for your help ! Have a good day

if you need to access these 2 directories only, you would need to create 2 samba shares. Lets edit your smb.conf again.

nano /etc/samba/smb.conf

remove the whole [dietpi] section at the end and replace it as follow.

[minecraft]
        comment = Minecraft Share
        path = /root/minecraft
        browseable = yes
        create mask = 0775
        directory mask = 0775
        valid users = root
        writeable = yes
        max connections = 2

[mnt]
        comment = Mount Share
        path = /mnt
        browseable = yes
        create mask = 0775
        directory mask = 0775
        valid users = root
        writeable = yes
        max connections = 2

don’t forget to restart your samba server

systemctl restart smbd.service

Thanks you so much ! Everything is perfect now. Have a good day !!!

Your welcome