I want to mount a SMB share with different user credentials. Therefore I want to use
mount -o nodev,nosuid -t smbfs //user:pass=<word@host/share /mnt/share
However, this command fails:
-bash: word@host/share: No such file or directory
When trying to pass the password via a variable, I get:
$ export PWD="pass=<word"
$ mount -o nodev,nosuid -t smbfs //user:$PWD@host/share /mnt/share
mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument
mount
on other systems seems to accept username and password as mount options, like:
$ mount -o nodev,nosuid,domain=mydomain,username=user,password="pass=<word" -t smbfs //host/share /mnt/share
or via a credentials file:
$ cat credentials.txt
username=user
password=pass=<word
domain=mydomain
$ mount -o nodev,nosuid,credentials=./credentials.txt -t smbfs //host/share /mnt/share
However, both ways are not available with macOS' mount:
mount_smbfs: -o credentials: option not supported
mount_smbfs: -o domain: option not supported
mount_smbfs: -o username: option not supported
mount_smbfs: -o password: option not supported
So the question is: How to provide the password to macOS' mount_smbfs? I'm aware that changing the password would solve the problem, but for reasons this is not an option.
Best Answer
Slightly offtopic, but maybe useful if you want to stick to putting credentials with special chars in a Shell variable. Regarding your bash commands I will point you to several topics:
Example:
${variablename}
. (Bourne Shell style)open 'smb://username:password@server/share'
- it creates the volume mount for you. If you omit the password, Finder will ask you for it.