Connecting to an SMB server from the command line in OS X
I had a call yesterday, where someone was asking to SSH into a remote Mac workstation and mount a particular fileshare on that workstation. I had them do the following:
—–
1. Log into the Mac with your account login and password.
2. Create a folder inside your home folder named sharename to match the name of the share on the server
Note: You should only need to create this folder if it doesn’t already exist.
3. Use the following command to mount the share, using the new sharename directory as the mountpoint:
mount_smbfs //username@servername.example.com/share ~/sharename
4. You should be prompted for your account password.
5. The SMB share should mount and you should be able to access it via the sharename directory.
To unmount the server share from using the command line in OS X:
1. Log into the Mac with your account login and password.
2. Make sure you’re not in the ~/sharename directory.
3. Use the following command to unmount the sharename share from ~/sharename:
umount ~/sharename
—–
However, when mount_smbfs //username@servername.example.com/share ~/sharename was run, it didn’t connect and gave the following error:
mount_smbfs: server connection failed: No route to host
Trying mount_smbfs //username:password@servername/share ~/sharename also did not work. Same error, plus the user was understandably not happy with the idea of having his password in the clear.
After a bit more digging, I found the answer here. In 10.6, Apple had changed the mount_smbfs configuration so that it now expected the server’s workgroup or domain as part of the connection string. For anybody else that needs it, here’s how the command should be set up if the server is connected to an AD domain:
mount_smbfs //’DOMAIN;username’@servername.example.com/share ~/sharename
If you’re using a workgroup, it should be set up as:
mount_smbfs //’WORKGROUP;username’@servername.example.com/share ~/sharename
Your information about correct syntax after 10.6 was gold! Thanks a lot!
Unfortunately this doesn’t work in 10.10.x. If I create the directory in step 2, then the mount command elicits the error “File exists”. If I don’t, I get the error “No such file or directory”. It’s not happy either way.
Addendum to above (since there’s no edit button). The “File exists” error can occur if a previous mount attempt succeeded even if you don’t think it did. Use the ‘df’ command to list all your mounts and see if that’s the cause of that error.
Now my problem is that the volume is mounted but there are no files appearing when an ‘ls’ command is issued…
…aaaand final edit (apologies!) No files appearing might just be because the file share is empty. Relevant: https://en.wikipedia.org/wiki/Rubber_duck_debugging
How does this work when there is a space in the username? Would I need to create a bash file?
For a space use %20 where the space would be.
how to set password with username ?