Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Mount SMB shares from the command line UNIX
Here's how to quickly mount a network share via the command line. First, create a folder called "share" somewhere in your home directory (wherever). Then open a terminal and type
mount -t smbfs //user@server/sharename share
From the Finder, look in your home directory for the 'share' folder. It should appear to be an alias. Once you click it, the mounted volume will appear on your desktop.

Caveat: you may have to install Samba by way of Fink. I've not tested without Fink, and I ain't gonna. =]
    •    
  • Currently 3.70 / 5
  You rated: 1 / 5 (10 votes cast)
 
[224,880 views]  

Mount SMB shares from the command line | 29 comments | Create New Account
Click here to return to the 'Mount SMB shares from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
who to unmount
Authored by: Anonymous on Jun 10, '02 11:15:17PM

O.k. so I tried this hint out. Yes it worked. Now how do I unmount the share ? I've tried telling the share icon on my desktop to eject, but it claims to be in use. I have no files opened from the share.



[ Reply to This | # ]
how to unmount
Authored by: froz on Jun 11, '02 04:17:06AM

This seems to be a bug in 10.1.5 Normally, you would find the share mounted in /Users/name/share (if you followed the original hint) and would unmount it with:

sudo umount /Users/name/share

However, this does not work. I was able to remove the share by making a second connection in the Go menu Connect to Server and then dragging the
new share icon to the trash, e.g:

I connected to smb://workgroup;hostname/mp3 which is the same share I had mounted as "share". When I tossed the mp3 icon, I got a volume in use error, but both the mp3 and share icons disappeared.





[ Reply to This | # ]
who to unmount
Authored by: robpoll on Jul 02, '02 01:41:44PM

I don't know if you have received an answer but I just found out how to do this and thought I would share.
I tried to use umount /<directory where share is mounted> and it didn't work. The reason I knew it didn't work was because I mounted the share with the Connect to server option in the finder and it would append a "-1" to the share name. I used the mount command without parameters and saw that it still had the share mounted at /Volumes/share. I used umount /Volumes/share and it worked fine.
HTH,

Robert Pollard



[ Reply to This | # ]
tutorial
Authored by: VEGx on Jun 11, '02 02:27:46AM

Would someone please make a small tutorial of this. An example, for instance. For example, what is the "sharename." And is it just me who can access the other one's files now or if it is two way sharing? And if it works with PCs too. We've tried to share files on my cousin's PC and no luck so far. Haven't tried this hint yet.



[ Reply to This | # ]
using mount_smbfs
Authored by: monkeyvoodoo on Jun 11, '02 05:33:54AM
'mount -t smbfs' is really just a pointer to 'mount_smbfs', and everything works just fine under 10.1.5 (actually, 10.0 through 10.1.5...), assuming you do things right (i.e. have your permissions set correctly and whatnot).

mounting an smb share should be as easy as:

mount_smbfs //user@servername/share /Volumes/share

where "servername" is the NetBIOS name of the server (an IP address may also be substituted), "user" is a valid user on that server, and "share" is the name of the share you wish to mount locally (you'll most likely have to create the /Volumes/share directory)

I'll also note that if you place your mount in the /Volumes directory, Finder.app will see it, and place an icon for it on the desktop (assuming your Finder preferences are set to place shared volumes on the desktop). If the share isn't appearing on your desktop, use the Go to folder... command in the Go menu in the Finder, and point it to /Volumes, the share will appear on the desktop as soon as you click on its icon in the Finder.

doing a manual mount like this will leave Finder.app unable to unmount the share, but if you feel the need to manually mount a share, you should of course be prepared to manually unmount it using:

umount /Volumes/share

If you are still having troubles unmounting the share, unmount as root:

sudo umount /Volumes/share

none of this functionality requires anything remotely related to fink, as it is standard Darwin functionality



[ Reply to This | # ]
addendum: using mount_smbfs
Authored by: monkeyvoodoo on Jun 11, '02 05:40:31AM
You really shouldn't need to manually mount an SMB volume in OSX. From the Finder, in the Go menu, choose Connect to server..., and input:
smb://servername/share
into the Address field.

The only time you should ever need to manually mount a share is if the share name has a space in it, or you need to specify some really weird SMB options, which in most cases, nobody would need to do.

[ Reply to This | # ]

addendum: using mount_smbfs
Authored by: balthisar on Jun 11, '02 06:13:43AM

On the other hand, mounting it manually is a good way to emulate the Windows "reconnect on startup" to networked drives. I can't remember the file offhand, but I already have "special" mounts for my /Users partition, and I'm sure all of the swap-drive hacks are similar. Putting in the mount_smbfs there would connect to the other computer every time you start up. I imagine this would happen for every user, though, which may not be a good thing. Likewise, if the volume is not available, it may not be to graceful when it tries to mount. I'll have to look into this, because my 60GB iMac drive is getting kinda full, and my Windoze-box is near emtpy -- plenty of extra storage there!



[ Reply to This | # ]
addendum: using mount_smbfs
Authored by: kerim on Jun 11, '02 07:33:04AM

Wouldn't this hint make it easy to create an applescript of some sort that would automatically mount the same share every time. This could be faster than having to use the Go menu.

I wish mounting shared volumes worked like iDisk ...



[ Reply to This | # ]
addendum: using mount_smbfs
Authored by: rah on Jun 11, '02 09:35:10PM

You could add it to a .profile/.login, then fire up a shell.



[ Reply to This | # ]
addendum: using mount_smbfs
Authored by: bkperry on Jun 11, '02 01:17:16PM

Sometimes I find it faster to copy files through the command line to windows shares. So, if I'm there, I mount the share that way.



[ Reply to This | # ]
addendum: using mount_smbfs
Authored by: nevermind on Aug 18, '02 04:35:47PM

Use %20 for a space in your shares.

See: http://kbase.info.apple.com/ and search for 106471 to get the appropriate knowledge base document "Mac OS X 10.1: How to Connect to an SMB Volume (Microsoft Windows)"



[ Reply to This | # ]
using mount_smbfs: Printing to smb printer shares??
Authored by: TXLogic on Jun 11, '02 10:51:38PM
Dandy -- now does anyone know how to print to a samba printer share?


I've set up my linux box as a samba server on a wireless network and it works beautifully as a file server to my partner's Windows 2000 laptop and my OS X iBook, but only my partner's machine can see and print to the printer (via samba) that is attached to the linux box. The ignominy! Anyone have a solution to this? I've searched the net and Google Groups far and wide...it's gotta be possible...


TXLogic


[ Reply to This | # ]

using mount_smbfs
Authored by: froz on Jun 13, '02 04:58:38AM

Well, I still maintain there is a bug here. I realize "whatnot" covers a lot of ground, but on any other version of Unix, you can mount a share anywhere you want and unmount it at will. In OS X, you get a cute icon on the desktop if you do a "normal" mount, .e.g. /Volumes/whatever, but if you follow the instructions in the original post, you don't get the icon until you click on the share and then you can't unmount the share.

Permissions has nothing to do with it and remounting the share on a different mount point should not suddenly allow the original mount to go away, especially since there is an "in use" error message, but it still unmounts, hence the bug.



[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: dwarne on Jun 11, '02 10:27:12AM

Applescript can also be used to very easily mount SMB shares. You can either put the applescript icon on your desktop for double-click access, or you can put it in your login items.

The exact applescript is as follows (simple!)

tell application "Finder"
open location "smb://user:password@computername/sharename"
end tell

For example...

tell application "Finder"
open location "smb://administrator:danwarne@mailserver/c"
end tell

[ Reply to This | # ]

Using Applescript to mount SMB shares
Authored by: zedwards on Jun 11, '02 04:06:47PM

So simple, so obvious, yet so overlooked. This tip deserves to be on the main page.



[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: unxmaal on Jun 11, '02 04:42:28PM

Ouch! Schooled by both dwarne and monkeyvoodoo on the same tip!

Thanks though. This applescript rocks!



[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: SamW on Oct 18, '02 10:25:24AM

I have used the above and it works wonderful. how ever since i have upgraded a computer to 10.2 it seems not to work. I get the following error: "Finder got an error: an error type of -10814 has occurred" The exact script is as follows:

tell application "Finder"
open location "smb://henry/student"
end tell

I thought I was alone until some students have also reported the same error on their 10.2 systems.

Any help would be appreciated.

Sam



[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: russh on Oct 29, '02 10:25:03PM

I think that things changed in Applescript 1.9. This format works for me in 10.2.1:

try
mount "smb://myname:passwd@server.domain.com/sharename"
end try

Hope that helps.



[ Reply to This | # ]
? Disconnect/Umount SMB shares using Applescript in 10.2/Jag ?
Authored by: bartelsrausch on Jan 17, '03 02:35:46AM

How would I dissconnect shares using Applescript? I connected them using the applescript command to /Volumes/<sharename>.
thanks for any help, thorsten



[ Reply to This | # ]
? Disconnect/Umount SMB shares using Applescript in 10.2/Jag ?
Authored by: serversurfer on Sep 13, '03 09:56:05AM
Try this:

tell application "Finder"
    eject (every disk whose name is "sharename")
end tell


---
Love,
The Surfer

[ Reply to This | # ]

Using Applescript to mount SMB shares
Authored by: limulus on Oct 06, '03 12:41:37AM

The correct syntax is "mount volume".

I found this useful to create a Favorite for a WebDAV volume hosted on a nonstandard port.



[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: hartmurmur on Jan 21, '04 04:37:26PM
Is the process any different when you need to log in to a machine on a differnt domain that what you are in? I need to connect to a machine across domains and to the root. The following does not work for me.

try
mount volume "smb://domain\\userid:password@ipaddress/drive$"
end try


[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: hartmurmur on Jan 21, '04 04:50:11PM
Nevermind. Found the answer in a different thread...

try
mount volume "smb://workgroup;userid:password@ipaddress/drive$"
end try
and also referenced at developer.apple.com: Using SMB on OS X

[ Reply to This | # ]
Using Applescript to mount SMB shares
Authored by: JoePrecious on Nov 20, '03 02:21:15PM

This is exactly what I need and works great.

Just one question (from an AppleScript newbie):-

Can you tell it not to actually open the Finder window as it now does it everytime I log in?

Thanks



[ Reply to This | # ]
Solution: No Finder Window
Authored by: forman on Jan 11, '04 09:12:17PM
Use the following Applescript to mount smb drives in the background without opening Finder windows. The mount point is automatically created in the /Volumes directory.
try
   mount volume "smb://user@server/share"
end try
For a user with a login name of "forman" on a server called "vortex" with SMB shares called "local" and "scratch" use the following script:
try
   mount volume "smb://forman@vortex/local"
   mount volume "smb://forman@vortex/scratch"
end try
Save the script as an application using the Script Editor and put it in System Preferences -> Accounts -> Startup Items to mount the drives when you log in.

Michael.

[ Reply to This | # ]
mount quitely
Authored by: gabrielradic on Oct 04, '04 05:38:08AM

To mount the share quietly using your keychain record, use:

osascript -e "try" -e "mount volume \"smb://user@server/share\"" -e "end try"



[ Reply to This | # ]
Mount SMB shares from the command line
Authored by: sravanthi on Jan 25, '08 05:56:51AM

I followed the same steps as you mensioned , still getting the following error

mount_smbfs: tree connect phase failed: syserr = No such file or directory
mount_smbfs: tree connect phase failed: syserr = No such file or directory

Thanks in advance.



[ Reply to This | # ]
Mount SMB shares from the command line
Authored by: ckempke on Mar 30, '10 09:53:53AM

A much easier way to mount a volume at startup time: Mount the volume once, then open System Preferences->Accounts->Login Items and drag the volume into the list. No Applescript or command line work needed; the Finder just does it for you.



[ Reply to This | # ]
Mount SMB shares from the command line
Authored by: xylo on Nov 07, '10 02:41:49AM

Why complicate your life?

Use earlier : AutomountMaker



[ Reply to This | # ]