Samba - how change path to external HDD drive ?

Hello guys,

I am new to linux and dietpi, i would like to help with following problem,

I have installed samba via dietpi-software, i can access samba with username “dietpi” + pass. But I would like to change the path to my external hard drive.

I have mounted my ext drive with:

sudo mount /dev/sda1 /media/SSD

And i have also changed path in samba config with:

sed -i '/path = /c\path = /media/SSD' /etc/samba/smb.conf
systemctl restart nmbd smbd

But I can’t access samba anymore. Thanks for your help. What am I missing? THANKS :sunglasses:

ls /media/SSD is showing folders, and i can also access them. (I am using also Nextcloud)

Pls share following

ls -la /media/SSD
cat /etc/samba/smb.conf
lsblk -o name,fstype,label,size,ro,type,mountpoint,partuuid,uuid
systemctl status nmbd smbd
ss -tulpn | grep LISTEN
root@DietPi:~# la -la /media/SSD
-bash: la: command not found
root@DietPi:~# la -la /media/SSD
cat /etc/samba/smb.conf
lsblk -o name,fstype,label,size,ro,type,mountpoint,partuuid,uuid
systemctl status nmbd smbd
ss -tulpn | grep LISTEN
-bash: la: command not found
[global]

	workgroup = WORKGROUP
	server string = %h server
	dns proxy = no
	log file = /var/log/samba/log.%m
	max log size = 1000
	syslog only = no
	syslog = 0

	panic action = /usr/share/samba/panic-action %d

	security = user
	encrypt passwords = true
	passdb backend = tdbsam
	obey pam restrictions = yes
	unix password sync = yes

	passwd program = /usr/bin/passwd %u
	passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
	pam password change = yes
	map to guest = bad user

	load printers = no
	printcap name = /dev/null
	disable spoolss = yes

[dietpi]
	comment = DietPi Share
path = /mnt/dietpi_userdata
	browseable = yes
	create mask = 0664
	directory mask = 0775
	valid users = dietpi
	writeable = yes
max connections = 8
NAME FSTYPE LABEL   SIZE RO TYPE MOUNTPOINT PARTUUID                             UUID
sda               111.8G  0 disk                                                 
└─sda1
     ext4   ssd   111.8G  0 part /media/SSD c1c2efc0-c5dc-01d4-e073-e160ee62ea00 bce71f79-ab89-4d50-8ba7-d265c6ce4c0b
mmcblk0
│                  29.5G  0 disk                                                 
└─mmcblk0p1
     ext4          29.4G  0 part /          89086adf-01                          8724794f-4966-4eeb-9e56-4eab78d3c318
● nmbd.service - Samba NMB Daemon
     Loaded: loaded (/lib/systemd/system/nmbd.service; disabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/nmbd.service.d
             └─dietpi-services_edit.conf
     Active: active (running) since Sat 2021-11-13 11:09:36 GMT; 1h 34min ago
       Docs: man:nmbd(8)
             man:samba(7)
             man:smb.conf(5)
   Main PID: 8701 (nmbd)
     Status: "nmbd: ready to serve connections..."
      Tasks: 1 (limit: 2067)
     Memory: 2.7M
        CPU: 491ms
     CGroup: /system.slice/nmbd.service
             └─8701 /usr/sbin/nmbd --foreground --no-process-group

Nov 13 11:09:35 DietPi systemd[1]: Starting Samba NMB Daemon...
Nov 13 11:09:36 DietPi systemd[1]: Started Samba NMB Daemon.

● smbd.service - Samba SMB Daemon
     Loaded: loaded (/lib/systemd/system/smbd.service; disabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/smbd.service.d
             └─dietpi-services_edit.conf
     Active: active (running) since Sat 2021-11-13 11:09:36 GMT; 1h 34min ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
    Process: 8702 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (code=exited, status=0/SUCCESS)
   Main PID: 8711 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 3 (limit: 2067)
     Memory: 4.6M
        CPU: 1.638s
     CGroup: /system.slice/smbd.service
             ├─8711 /usr/sbin/smbd --foreground --no-process-group
             ├─8713 /usr/sbin/smbd --foreground --no-process-group
             └─8714 /usr/sbin/smbd --foreground --no-process-group

Nov 13 11:11:51 DietPi smbd[8715]: pam_unix(samba:session): session closed for user dietpi
Nov 13 11:11:54 DietPi smbd[8858]: pam_unix(samba:session): session opened for user dietpi(uid=1001) by (uid=0)
Nov 13 11:16:11 DietPi smbd[8858]: pam_unix(samba:session): session closed for user dietpi
Nov 13 11:18:28 DietPi smbd[9548]: pam_unix(samba:session): session opened for user dietpi(uid=1001) by (uid=0)
Nov 13 11:22:48 DietPi smbd[9548]: pam_unix(samba:session): session closed for user dietpi
Nov 13 11:39:32 DietPi smbd[10948]: pam_unix(samba:session): session opened for user dietpi(uid=1001) by (uid=0)
Nov 13 11:39:48 DietPi smbd[10948]: pam_unix(samba:session): session closed for user dietpi
Nov 13 11:42:31 DietPi smbd[10951]: pam_unix(samba:session): session closed for user nobody
Nov 13 11:42:36 DietPi smbd[10961]: pam_unix(samba:session): session opened for user dietpi(uid=1001) by (uid=0)
Nov 13 11:48:42 DietPi smbd[10961]: pam_unix(samba:session): session closed for user dietpi
tcp   LISTEN 0      50           0.0.0.0:445       0.0.0.0:*    users:(("smbd",pid=8711,fd=44))       
tcp   LISTEN 0      80         127.0.0.1:3306      0.0.0.0:*    users:(("mariadbd",pid=7754,fd=19))   
tcp   LISTEN 0      50           0.0.0.0:139       0.0.0.0:*    users:(("smbd",pid=8711,fd=45))       
tcp   LISTEN 0      511        127.0.0.1:6379      0.0.0.0:*    users:(("redis-server",pid=7690,fd=7))
tcp   LISTEN 0      1024         0.0.0.0:80        0.0.0.0:*    users:(("lighttpd",pid=7868,fd=4))    
tcp   LISTEN 0      1000         0.0.0.0:22        0.0.0.0:*    users:(("dropbear",pid=378,fd=4))     
tcp   LISTEN 0      50              [::]:445          [::]:*    users:(("smbd",pid=8711,fd=42))       
tcp   LISTEN 0      511            [::1]:6379         [::]:*    users:(("redis-server",pid=7690,fd=8))
tcp   LISTEN 0      50              [::]:139          [::]:*    users:(("smbd",pid=8711,fd=43))       
tcp   LISTEN 0      1024            [::]:80           [::]:*    users:(("lighttpd",pid=7868,fd=5))    
tcp   LISTEN 0      128                *:21              *:*    users:(("proftpd",pid=3203,fd=0))     
tcp   LISTEN 0      1000            [::]:22           [::]:*    users:(("dropbear",pid=378,fd=5))

ls -ls /media/SSD:

root@DietPi:~# ls -ls /media/SSD
total 32
 4 drwxr-x--- 3 www-data www-data  4096 Nov  8 12:12  AndroidBackupy
 4 drwxr-x--- 3 www-data www-data  4096 Nov  8 07:17 'Fotky a videa'
16 -rwxr-x--- 1 www-data www-data 12337 Nov  2 14:10  test.ods
 4 drwxr-x--- 4 www-data www-data  4096 Nov 13 07:19  ISF
 4 -rw-r--r-- 1 www-data www-data     1 Nov 12 13:16  Readme.md

Sorry there was a typo on the first command (corrected now)

But samba seems running fine. Services are active and Samba is listen on correct port. Just your samba configuration file is still pointing to the default DietPi user data directory.

Yes, and that’s what i am asking for. How can i change the directory to /media/SSD when i logged in with user “dietpi”. Thanks

I wrote, that i can connect to samba server without issues, i just need to change the folder.

root@DietPi:~# ls -la /media/SSD
total 40
drwxr-x--- 5 www-data www-data  4096 Nov 13 10:42  .
drwxr-xr-x 3 root     root      4096 Nov 12 12:12  ..
drwxr-x--- 3 www-data www-data  4096 Nov  8 12:12  AndroidBackupy
drwxr-x--- 3 www-data www-data  4096 Nov  8 07:17 'Fotky a videa'
-rwxr-x--- 1 www-data www-data 12337 Nov  2 14:10  test.ods
drwxr-x--- 4 www-data www-data  4096 Nov 13 07:19  ISF
-rw-r--r-- 1 www-data www-data     1 Nov 12 13:16  Readme.md

Usually this command should do

sed -i '/path = /c\path = /media/SSD' /etc/samba/smb.conf
systemctl restart nmbd smbd

Is it not working in you case?

If not you can change path variable manually

nano /etc/samba/smb.conf

Did you read my first message? I have tried this :slight_smile:. Path is changed.

But i can’t access folder / smb share after i change the path. There is some problem with permissions maybe?

The Solid Explorer is saying “Access denied” when i click on Dietpi folder. Thanks

partically solved, i can see the folder, but can’t write / copy files on drive

sudo chmod -R 0755 /media/SSD

A little bit expected as all folder on SSD are owned by user www-data? Hence user dietpi has no write access :wink:

You could add user dietpi into web server group www-data. As well write permission would be needed on group level.

Or change the owner to dietpi, as it doesn’t look like what you want to serve via web server?

Thank you guys for your replies, sorry i was out of my home,… nowi will take a look on it. :sunglasses:

Can you please tell me how can i add the user “dietpi” into web server group www-data ? Thanks

/edit: I have tried this command, is that right? Added dietpi user to www-data group

root@DietPi:~# sudo adduser dietpi www-data
Adding user `dietpi' to group `www-data' ...
Adding user dietpi to group www-data
Done.
root@DietPi:~# id dietpi
uid=1000(dietpi) gid=1000(dietpi) groups=1000(dietpi),33(www-data)

and reboot, but still can’t write to /mnt/SSD via SMB. (Permissions denied) With dietpi user logged in

You cannot write there because you do not grant members of the www-data group write permissions, only the www-data user:

drwxr-x---

This means a directory “d” with read+write+execute permissions for the owner (rwx), but only read+execute permissions for group members (r-x) and no permissions for anyone else (—).

The question is why is a media drive owned by the webserver user? Doesn’t make it sense to change this to be owned by the dietpi user? Else:

chmod -R g+rw /media/SSD

So you add read+write permissions for group members.

I have installed nextcloud. Maybe that’s the reason? I was just following tutorials :slight_smile:

I don’t know what will happen, if i change it to dietpi user. I Think it will not be possible to use nextcloud app / web to write and use /media/SSD, or am I wrong ?

So what do you recommend to me? THANKS ! :wink:

/edit: I have tried to
sudo chown -R dietpi:dietpi /mnt/SSD

and as i said, can’t write/edit anything in nextcloud in that folder /mnt/SSD

I am sorry that i have not mentioned this information at the begining. (NEXTCLOUD installed)

You use Nextcloud to write to that directory? Yes that is a good explanation. However, note that the Nextcloud data directory is not meant to be touched directly but only through Nextcloud. Otherwise, if you now create new files or change them through Samba, Nextcloud doesn’t know about it and has the old information stored in its file index database. So you will have more and more missing, false and obsolete information in Nextcloud. There are storage extensions available for Nextcloud, at least for adding a remote Samba share, but not sure whether there is one which provides Nextcloud data through a local Samba server natively. But webdav is what Nextcloud natively uses, so webdav clients can be used as alternative, and of course the official Nextcloud clients.

So in short: Do not share the same data via Nextcloud and Samba concurrently. You should be able to find Nextcloud compatible clients for all thinkable platforms.

Maybe i know exactly what are you trying to tell me… And Iunderstood :slight_smile:

My goal was that i will use one external SSD for Nextcloud data and this drive will be also shared via SMB. Nevermind…

And what about creating 2nd folder /media/SSD/SMB with sudo chown -R dietpi:dietpi /media/SSD/SMB. Is that bad / wrong idea? I would rather ask, then do some mistake / security etc…

I really appreciate your help to me.

Sharing it as read-only data btw is not an issue, but whether this makes sense instead of native Nextcloud client or webdav client is another question.

Ah indeed the whole drive doesn’t seem to be the Nextcloud data directory, as this contains some specific files and directories, most importantly the .ocdata file as marker, like here:

# ls -Al /mnt/sda/ncdata/
total 44K
-rw-------  1 www-data www-data  542 Nov 20 15:19 .htaccess
-rw-------  1 www-data www-data    0 Nov 20 15:19 .ocdata
drwx------  7 www-data www-data 4.0K Sep  7  2019 XXXXX
drwx------  8 www-data www-data 4.0K Aug 11  2019 Micha
drwx------ 12 www-data www-data 4.0K Nov 15 18:53 appdata_XXXXX
drwx------  2 www-data www-data 4.0K Dec 16  2020 files_external
-rw-------  1 www-data www-data    0 Nov 20 15:19 index.html
-rw-r-----  1 www-data www-data 1.8K Nov 20 15:42 nextcloud.log
drwx------  2 www-data www-data 4.0K Nov 19 17:02 tmp
drwx------  4 www-data www-data 4.0K Nov 19 00:18 updater-XXXXX
-rw-------  1 www-data www-data    0 Nov 20 15:42 updater.log

So basically it then makes sense to have only the Nextcloud data (sub) directory itself owned by www-data and either everything else (on the drive) or a dedicated sub directory for Samba owned by “dietpi”. So depending on your needs to can either share a dedicated sub directory via Samba or the whole drive, but with read-only access to the Nextcloud data directory.

Thanks, i will do it in that way:

1 SSD Drive mounted as /mnt/SSD, with 2x FOLDERS: NEXTCLOUD and NAS. Nextcloud folder with www-data group premissions, and NAS with dietpi user permissions.
And SSD Drive /mnt/SSD, will have rootpermissions, right? Or dietpi ?

Thanks for your time!

Yes that will work very fine and clean. If only /mnt/SSD/NAS should be writable for Samba, then it makes sense to keep the /mnt/SSD owned by root. So you can add other sub directory for other purposes and have each service cleanly permitted to write to its own intended directory only.

Thanks, i have done it, but i can’t figure why SMB is not working, i can’t even see the folders (Premissions problem)
If I set root permissions on /mnt/SSD , the nextcloud isn’t working, even when i set www-data permissions on the folder mnt/SSD/NEXTCLOUD…

So i did following,
sudo chown -R www-data:www-data /mnt/SSD/
sudo chown -R dietpi:dietpi /mnt/SSD/NAS

sed -i ‘/path = /c\path = /mnt/SSD/NAS’ /etc/samba/smb.conf
systemctl restart nmbd smbd

OUTPUT:
ls -ls /mnt/SSD

total 24
 4 drwxrwxr-x 23 dietpi   dietpi    4096 Nov 21 14:59 NAS
 4 drwxrwxr-x  5 www-data www-data  4096 Nov 21 11:52 NEXTCLOUD
16 drwx------  2 www-data www-data 16384 Nov 21 14:06 lost+found

This is my last block in smb config: /etc/samba/smb.conf
[dietpi]
comment = DietPi Share
path = /mnt/SSD/NAS
browseable = yes
create mask = 0664
directory mask = 0775
valid users = dietpi
writeable = yes
max connections = 8



It that way the Nextcloud works, but samba not. Thanks!

It seems that this command solved the problem:
sudo chmod -R 0755 /media/SSD

Is that okay?