Your own personal IT department

How to find which SAMBA user has locked a file

Whilst the quickest way to unlock all files is to restart samba, it will result in all users temporarily disconnecting from the server, potentially resulting in data loss. To restart samba, run:
/etc/init.d/samba restart
(Command may be different depending on the Linux distribution)

The better option is to find which user has the file open and either get them to close it or kill their Samba process which is locking the file.

First run:
smbstatus
and find the locked file. Note PID number (first column)
smbstatus

If list is very long and you are struggling to find the file run:
smbstatus | grep -i filename.ext
where filename.ext is name of the locked file.
This will filter the smbstatus results and return only lines with your locked file.

Now run smbstatus again (or return to the first query) and in the top table find the user with the PID number you noted. This will be the user the who is locking the file.

ie smbstatus | grep -i {PID}

smbstatus
You can also check what other files this user has opened by inspecting smbstatus results or running:

smbstatus | grep 14899
where 14899 user’s PID number

If possible, ask user to close all files opened from this particular server.
Finally, to unlock all files this user has opened, run

kill 14899
where 14899 user’s PID number