Closed - Unable to delete file from mounted location (SMB share) as root
Samba does not represent the correct File Permissions on the Client Machine for the Samba Share.
Accessing the Files on the Samba Server over a Samba Connection you access them as the Samba User even if you are Logged In as root
User on the Client Machine.
Changes you make to the Files over the Samba Connection are not reflected in that way on the Samber Server.
Try to login over ssh
to the Samba Server and see the real File Permissions.
Probably those Files belong to a different User and/or different Group on the Samba Server.
In your Samba Share Configuration [Space]
you do not define any User or Group asignation, so other Users connected to the same Samba Share create those files with their own System User Account and their own User File Permissions.
Related videos on Youtube
![Marialena](https://i.stack.imgur.com/4d4QC.jpg?s=256&g=1)
Marialena
Updated on September 18, 2022Comments
-
Marialena almost 2 years
UPDATE: It seems like the problem was caused because of another service which had nothing to do with smb. Apologies for not having a proper resolution and I am just closing the issue.
I have mounted a share with SMB to an Ubuntu 17.10 VM and I am trying to delete a file from the mount location (
/mnt/smb_mnt
).I have first did the mount as guest:
sudo mount -t cifs //ipaddress/share /mnt/smb_mnt/ -oguest,vers=2.0
and as aroot
too and none of it worked. Also, I tried themount -o remount,rw /mnt/smb_mnt
to remount using read and write privileges but the file can still not be deleted.I give the file 777 permissions and I execute the
rm
command asroot
which is also the owner of the file. I checked withls -l
and the permissions are the ones I assign to both file and parent file (smb_mnt
)I have tried to use
chattr -i
command based on other related questions I have found but I get:chattr: Permission denied while setting flags on /mnt/smb_mnt/file
.What else can I try to be able to achieve the deletion?
I know files can be deleted easily locally on the machine, but I need to delete the file from the mounted location because the module I want to test works only over smb so I can't just
ssh
to the machine and delete the file manually.Here is the SMB config file:
[global] # Include the base global configuration options. These don't usually change. include = /etc/samba/base_global.conf # These are configurable via the module max protocol = SMB2 hide files = //:2eDS_Store/:2eFBCLockFolder/.FBCLockFolder/:2eFBCIndex/.FBCIndex/TheVolumeSettingsFolder/TheFindByContentFolder/Temporary Items/Network Trash Folder/.AppleDB/:2eVolumeIcon.icns/.VolumeIcon.icns/Icon/.AppleDouble/.AppleDesktop/desktop.ini/RECYCLER// # (Options from the currently enabled Global Profile. Will overwrite any previous options) # Enabled Global profile: Default Global # Authentication is handled by the UserDirectory module. # The "security" option is put in this file as well. include = /etc/samba/auth.conf [Space] # Profile: Guest Read/Write path = /share/Space guest ok = True read only = False browseable = True preexec = /opt/space/modules/SMB/bin/scripts/event.py --event connect --profile 105 --service %S --user %u --client-ip %I --server-ip %i --path %P --pid %d root preexec = /opt/space/modules/SMB/bin/scripts/event.py --root --event connect --profile 105 --service %S --user %u --client-ip %I --server-ip %i --path %P --pid %d postexec = /opt/space/modules/SMB/bin/scripts/event.py --event disconnect --profile 105 --service %S --user %u --client-ip %I --server-ip %i --path %P --pid %d # Optional extra definitions created by other programs. # Will scan /etc/samba/includes.d/ for extra configuation files as well # A SMB.createConf() will need to be run for it to detect new SMB config files # The first line (includes.conf) is included for backwards compatibility. Modules should use the includes.d folder and make their own files. include = /etc/samba/includes.conf
-
Jaroslav Kucera about 6 yearsIt also depends how is the share shared, ie. if it's just read only, you won't be able to delete anything.
-
Marialena about 6 yearsit is not read-only, I have checked the SMB config options
-
Jaroslav Kucera about 6 yearsAnd can you share those SMB config options?
-
Marialena about 6 yearsI have just added it to my question @JaroslavKucera . Thank you
-
-
Marialena about 6 yearsthat was very very useful, thank you. After I
ssh
the permissions wherenobody
even if I changed it toroot
from my VM. How can i sync these permissions through the SMB config file? I have tried to doumask 000
,chmod 777
to the file from thessh
and thensudo su -
from my VM andrm -r
but i still get permission denied. -
Bodo Hugo Barwich about 6 yearsThere are several ways you can manage the Ownership and the Permissions for Files created through Samba Connections within the Samba Configuration File. Setting up allowed Groups
valid users
,write list
,force user
and define Default File and Directory Permissions withcreate mask
anddirectory mask
. Important for the allowed Groups and Users is the System User Account on the Samba Server with which you connect to it. -
Marialena about 6 yearsthanks. I have added this to the config file of SMB (each one in a new line) for the share I work on:
create mask = 0777 directory mask = 0777 force create mode = 0777 force directory mode = 0777 write list = root read list = root
. I changed the config file on the machine directly. The machine has ownernobody
and in the VM/mnt
the owner isroot
. I still can't delete any files even if I change the owner toroot
in the machine withchown
or even if I change in/mnt
of my VM the permissions to777
(-rwxr-xr-x
while in the machine is-rw-rw-rw-
if i don'tchown
toroot
) -
Bodo Hugo Barwich about 6 yearsSamba works similar to FTP you log in to the Server over a User Account that exists on the Samba Server where you want to place the files on. If your Client Machine does not have the same User Account as the Samba Server certainly you are logged in as Anonymous User. From Command Line I usually use this Command to access the Samba Server temporally
smbclient //samba-server/share/ -U user-account
This will you log in into the Samber Server asuser-account
User. This can be different than the current User Session on you Client Machine. -
Marialena about 6 yearsI have accessed the smb share files in that way but how can my automated python scripts execute unix commands in that system like I was doing in the mounted smb location?
-
Bodo Hugo Barwich about 6 yearsI don't know what kind of task you want to execute on the Samba Share. To mount the Share permanently to your system I suggest to use the File Browser with the Custom Location
smb://user-account@samba-server/share/
. You would have mount the Share before you run your Script. Or to look at this Python Library which is discussed in another Question stackoverflow.com/questions/45184452/…