Score:0

How mount (cifs) in Ubuntu a MacOS directory with all permissions

kz flag

About mount purposes

If the client and server are both Linux (Ubuntu), and assuming that the user in the server is omicron with uid 1007 gid 1007 the following command is viable to be executed in the client:

sudo mount -t cifs //192.168.1.X/samba_alias
                   /mnt/192.168.1.X/directoryname       
                   -o username=omicron,
                   rw,
                   uid=1007,
                   gid=1007

uid and gid are mandatory to be the same than omicron in the server otherwise is not possible create anything in the mounted directory. So, because any new files created from the client have the same uid and gid than the server's user, then the server can use them without any problem.

If the server is MacOS and client Ubuntu.

If through the GUI is used smb://hostname/directorynameshared, it is mounted, and is possible create anything and execute any script, it in:

*$XDG_RUNTIME_DIR/gvfs/smb-share:server=hostname,share=directorynameshared

The unique disadvantange is that in the server is not possible edit/access that new content because the user/groups are not the same, it is solved with chown in the server side. Anyway the directory is unmounted later.

Now, the reason of this post, if the following is used (Ubuntu to MacOS) - user in the server is omicron with uid 505 gid 507:

sudo mount -t cifs //192.168.1.X/directorynameshared
                   /mnt/192.168.1.X/directoryname       
                   -o username=omicron,
                   rw,
                   uid=505,
                   gid=507

Is possible execute the scripts, but is not possible create new content:

  • mkdir: cannot create directory ‘xyz’: Permission denied

How solve this situation?

Score:1
in flag

On the MacOS Samba server, you'll need to ensure the connecting account has "Full Read/Write" permissions to the shared directory. From there, this connection string will work for a manual mount situation:

sudo mount -t cifs -o uid=omicron,username=omicron,password=superSecretPassword!123 //192.168.1.X/directorynameshared /mnt/192.168.1.X/directoryname

Note that the uid and username values are both the literal name of the account on the MacOS machine, and the password value is also explicitly provided. I've not encountered a situation with a MacOS Samba host where the rw or gid flags are required when manually mounting a share.

If you plan on adding the mount to your /etc/fstab file, there are a few extra things you'll need:

//192.168.1.X/directorynameshared       /mnt/192.168.1.X/directoryname  cifs uid=505,gid=507,username=omicron,password=superSecretPassword!123,file_mode=0770,dir_mode=0770,nounix 0 0

Note that when the share is mounted via /etc/fstab, the uid and gid values are required, as well as flags for file_mode and dir_mode, plus nounix. The nounix flag is particularly important if your Ubuntu Server is going to be writing files via Apache and other service utilities.

Manuel Jordan avatar
kz flag
Thanks for the quick answer. Yes, on MacOS the new user created how `Standard` type is already applied/assigned to the directory to be shared with all the `"Full Read/Write"` permissions. And yes, the `uid`, `gid` and `username` are based on the server's user. - BTW Why I should use the `/etc/fstab` approach?
in flag
I never said you *should* mount via `/etc/fstab`; I offered it as an option. Generally servers are static devices that operate in the same location with the same resources for great lengths of time. As a result, people generally automate as much of the server configuration as possible so that time is not spent on the machine after any reboot or system update. If you do not wish to auto-mount, that is your choice
Manuel Jordan avatar
kz flag
Thanks, I've already done a research about that, it is for automatic mount.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.