Access and Mount an SMB Share via Command Line

Sep 24, 2009 - 4 Comments

terminal-icon-512x5122 OSXDaily reader Dan Luna sent in the following tip on accessing Windows shares on the Mac from the command line: “My Mac is nestled into a sea of Windows PC’s at the office, and so I am frequently accessing SMB shares to share data and files. Accessing SMB/Windows shares on the Mac is really easy from the GUI but I spend a lot of time in the command line and I always like to find a way to do things using the underpinnings of Mac OS X. With this in mind, here’s how to access SMB shares via the command line in OS X:”

This first command lists the available shares at the destination IP:

smbclient -U user -I 192.168.0.105 -L //smbshare/

(Note that some of the newer versions of OS X use “smbutil” instead of smbclient)

Now you’ll want to pass set your SMB shares mount point:

mount -t smbfs -o username=winusername //smbserver/myshare /mnt/smbshare

And finally you’ll want to gain access to the SMB share by specifying your Windows login and the machines IP address:

mount -t cifs -o username=winusername,password=winpassword //192.168.0.105/myshare /mnt/share

Thanks for the tip Dan! I haven’t been able to check if this works because I’m on an all Mac network, but the commands seem valid so I see no reason it wouldn’t. Obviously you’ll need to fill in your own unique usernames, sharenames, IP addresses, mount points, etc.

I really appreciate Dan’s tip but I think I’ll just stick to the GUI myself…

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. If you like being able to map those samba shares on the command line, you’ll love being able to do so from anywhere through a secure ssh tunnel like this:

    1st: set up the ssh tunnel from your mac to the machine hosting the samba share by typing this into your mac:

    screen sudo ssh -axC -c blowfish -l -L 139::139

    -this will establish a tunnel using compression and fast encryption, so port 139 on your mac now points to port 139 on the samba host.
    -you will see a terminal session logged on to the remote server. This needs to remain running. To get it out of your way (so you don’t have to leave that terminal window running) press A, and the ‘screen’ will detach – the process is now running in the background, you can close your terminal, or recall the session by entering ‘screen -r’ from any terminal session.

    2nd: mount your drive per the directions here, except that in place of the hosts’s ip, you enter ‘localhost’, sending the samba connection through the tunnel.

    Voila – it’s fairly fast, secure, and, best of all, it is usable through most corporate firewalls, since they will almost always allow ssh connections through, while often they do not allow ports 137, 139, & 445 (the samba ports) to cross the firewall.

  2. billspat says:

    instead check out mount_smbfs

    http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man8/mount_smbfs.8.html

    #example:
    mkdir /Volumes/winshare
    mount_smbfs //user@winserver.yournetwork.com /Volumes/winshare

    #… when you are done
    umount /Volumes/winshare

  3. [...] which is why this a different technique than what you use to mount an ISO in Mac OS X. You can also access and mount smb shares via the command line which allows for scripting possibilities, if you’re interested in a more technical approach. [...]

  4. DrTebi says:

    @billspat:
    mount -t smbfs actually calls mount_smbfs, however, the command in the article does not work (Mac OS X 10.6). It should be:
    mount -t smbfs //username@smbserver/myshare /mnt/smbshare

    The same works with mount_smbfs:
    mount_smbfs //username@smbserver/myshare /mnt/smbshare

    It should also be noted that sometimes the host name of a server is not known. In that case one can simply provide the IP address:
    mount_smbfs //username@10.0.0.34/myshare /mnt/smbshare

    The server will usually want a password. The mount_smbfs command will ask for that password automagically. But if you’re not concerned about security at all, you could provide it on the command line, too:
    mount_smbfs //username:password@smbserver/myshare /mnt/smbshare

    I do not recommend this though, since your Terminal saves all your commands in a history by default, and a user could simply type ‘history’ and see your password in one of the previous commands you typed.

    Cheers,
    DrTebi

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates