Samba is a free Linux/Unix software which provides file and print access for Microsoft Windows clients. If you have a Linux file server or Linux based NAS device on a network with Windows clients you are probably using Samba.

Samba deals with file locking, preventing file corruption and data loss when two or more clients try to simultaneously edit the same file. There may be situations where you need to force file unlock, for example when file was closed but lock was not properly released by Samba.

Unfortunately Samba doesn't allow unlocking individual files. There are couple of workarounds though.

Restart Samba

Quickest and most dirty way is to restart samba. Problem is that all users will be temporarily disconnected from the server, potentially resulting in data loss. To restart samba, run:
/etc/init.d/samba restart

Command may be slightly different depending on your Linux distribution.

Kill user's PID

Better option is to kill Samba process which is locking the file. Samba assign a separate process to every connected user. This way only files locked by that particular user will be unlocked. It won't drop the connection in the same way as restarting samba does.

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.

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

3 comments

  • I am new to Linux and so all this seems a lot of work for a simple fix IMHO. So all I do is..

    1. Right click on the locked file (Mine shows a padlock)
    2. Scroll down to .. "open root here"
    3. Choose the permission tab
    4. Enter read and right on both permissions

    Should be good to go. Only problem is you need this each time you transfer that file. Once you use that file it will now stay unlocked, or until next time you might update that same file from another box, as it will again be locked. Careful though when working with several users as it could end up loosing data by mistake. I am only user on my network so its easy, but I could discern some problems for multi users if you have no system in place. Happpy days.

    • Cant find a way to edit my post,

      but after step 2... you must right click on the file to choose Properties in order to see the Permissions tab. Sorry bout that.

Leave your comment

In reply to Some User
Captcha Image