Access and Mount an SMB Share via Command Line

Sep 24, 2009 - 4 Comments

Mac Terminal icon

Do you need to access and mount an SMB share from the command line on a Mac? You may be used to connecting to Windows PC from the Mac networking features to mount a Windows share on Mac, but you can also connect to Samba shares from the Terminal too.

This article will show several ways to mount and access SAMBA / SMB network shares from the command line of Mac, including with the latest MacOS versions and older Mac OS X releases too, as the process is different depending on the system you are using.

How to Access & Mount SMB Shares via Terminal on Mac

In newer macOS versions, you can can accomplish this with “mount_smbfs” command and it’s rather simple:

mount_smbfs //USER@192.168.0.105/myshare /mnt/smbshare

Replace USER, the IP address, the share name, and the share mount point, and that’s all there is to it.

Of course you’ll have to login and authenticate to the network share, unless it’s a GUEST user login.

You can also unmount the SMB share with the ‘unmount’ command as usual.

Accessing & Mounting SMB Shares in Older Mac OS X Versions

terminal-icon-512x5122 For older versions of Mac OS X, 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 Mac OS X:”

Earlier versions of Mac OS X could break this into several commands like so, to first list the available SAMBA 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 with later Mac OS releases, 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 and it’s a great advanced trick to use for terminal users, but for some Mac users who prefer the GUI then mounting Windows shared folders through Mac Finder is probably easier.

.

Related articles:

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

4 Comments

» Comments RSS Feed

  1. 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

  2. […] 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. […]

  3. 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

  4. 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.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

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

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site