brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: uid, gid and forceuid decide who owns the files of a cifs mount on Linux

Linux
~/tips/tip-cifs-uid-gid-forceuid

sudo mount -t cifs //server/share /mnt/share -o username=user,uid=1000,gid=1000,file_mode=0644,dir_mode=0755

Sets which local user owns the files on a mounted SMB share, and when the server may override it.

A freshly mounted SMB share often belongs to root, and then your own user cannot write to it. The reflex is chmod or chown, but on a cifs mount the mount options decide who owns the files. That is where I’d fix it.

sudo mount -t cifs //server/share /mnt/share -o username=user,uid=1000,gid=1000,file_mode=0644,dir_mode=0755

The mount.cifs man page says uid= sets the owner of all files and directories on the mount when the server does not provide ownership information. It takes a user name or a numeric uid. The default is uid 0, which is why everything shows up as root. gid= works the same way for the group.

The catch is in the wording “when the server does not provide ownership information”. If the server does send owners, for example a Samba server with the CIFS Unix extensions, those win. Add forceuid and forcegid to make the client ignore the server’s values and always use yours.

file_mode= and dir_mode= override the default modes, but the manual says only if the server does not support the CIFS Unix extensions. In /etc/fstab I’d use numeric ids, and you can look yours up with id -u and id -g. Non-numeric names need mount.cifs version 1.10 or higher.

Keep the password out of the command. Put it in a credentials file and point to it with credentials=, and see the existing tip on that here on the site. Check the result with ls -ln /mnt/share, which shows the numeric owners.

Further reading: mount.cifs(8) man page

Going deeper: Guide: your Unraid cache is full and Docker stopped, how to find out why and fix it

More Linux tips notify-send -r "$id" "Backup" "Done" pgrep -af 'sleep 301' smbstatus -L msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.example.com --port=587 smbclient //server/share -U user -Tc backup.tar "*" All Linux tips (283) All topics

Link