Operating systems

How do I... Connect a Mac OS X machine to a Samba share?

Working (or living) within a Linux-based network is become more and more commonplace. And with the popularity of Mac OS X rising, Apple-based computers have to play well inside a Linux network. With the help of Samba this is not only possible, it's easy to configure and establish. Jack Wallen takes a look at how a Mac OS X computer connects to a Samba share.

Working (or living) within a Linux-based network is become more and more commonplace. And with the popularity of Mac OS X rising, Apple-based computers have to play well inside a Linux network. With the help of Samba this is not only possible, it's easy to configure and establish. Let's take a look at how an OS X computer connects to a Samba share.

Before we get started I wanted to make note that this is not an in-depth article on setting up Samba. We will touch base on getting Samba up and running so the Mac OS X machine can connect to it, but primarily this is about OS X's ability to connect.

This blog post is also available in PDF form as a TechRepublic download.

Basic Samba configuration

The first thing you need to do is set up the Samba Security mode. This is located (in Fedora-based Linux distributions) in /etc/samba and the file is called smb.conf. You will have to have root access in order to make these modifications. So open up a console window, su to root, and open up the smb.conf file in your favorite editor.

The first option you are going to change is the workgroup option. Change this to match the workgroup you use on your network. The next option you need to do is change the security= option. We are going to change that option to security = user. The next option is the hosts allow option. You want to set this to the range used on your network.

For example: In my home network I use the 192.168.1.x address scheme. You might also want to allow for all localhosts.

Now scroll on down further in the smb.conf file to locate the [homes] section. This is where you configure the default location that will contain those logging into the Samba share. A typical configuration will look like Listing A.

Listing A

[homes]

comment = Home Directories

browseable = yes

writable = yes

read only = no

public = yes

Now the above section can cause you some security issues. You will want to make sure your network is secure and that the data housed in this Share isn't critical information. Why? Because you are making it available to anyone that has a Samba login name/password. Granted you get a modicum of control by only giving Samba usernames/passwords to trusted users.

For basic Samba configuration that is all you need to do with smb.conf. Now you need to add Samba users and passwords. These users and passwords will be used when a user attempts to log onto a Samba share from the Mac OS X machine. To add a Samba user you will run (on the Linux machine as root) the smbpasswd command:

smbpasswd -a USERNAME

At which point you will be prompted (twice) to enter a password. Once that is done you are ready to fire up the Samba daemon. To start the Samba daemon issue the command (again as root) /etc/rc.d/init.d/smb start which will start up Samba. You should get no errors.

Now you are ready to hop on over to your Mac OS X machine.

Connecting from Mac OS X

The first thing you need to do is open up a Finder window. (Figure A)

Figure A

Your standard Finder window
To quickly start a connection hit the [Apple] key and the [K] key together. You will then be prompted to enter a server address. As you can see in Figure B, you will enter the actual server IP address preceded by smb:// once you enter the information click OK.

Figure B

If you hit the + sign you can add this Samba server to your favorites list making connecting even easier
Now you are ready to select your SMB mount point. As we have configured in smb.conf our only available mount point is homes as shown in Figure C. So click OK to continue.

Figure C

If there are more mount points configured in smb.conf they will appear in the drop down list
Now you will be prompted for the username/password you added with the smbpasswd command as shown in Figure D. Enter this and click OK.

Figure D

Username and password

You can also add this username/password combination to your OS X keychain by clicking the checkbox. If this machine is shared, I do not recommend this option for security purposes.

Once the machine has connected to the Samba share you will see the directories/files appear in the Finder listing as well as a representative icon on the desktop. (Figure E)

Figure E

Because of the configuration in smb.conf your user should be able to read and write files to the Samba share

You are all set.

Now in order to disconnect from the Samba share you simple do a Ctrl-click and select Eject "HOMES" from the options. (Figure F) Once you do that your machine will disconnect from the Samba share.

Figure F

Disconnect

Another method of disconnecting is to click and drag the icon to the trash bin on the dock. You can also click the eject button associated with HOMES in the Finder.

Final thoughts

Connecting an OS X machine to a Samba share couldn't be any easier. Just remember to keep your security tight so that rogue users cannot gain access to your Samba shares. If you have more complex needs with Samba make sure you visit the Samba Web site for more information.

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

3 comments
pauljunior.jeanmarie
pauljunior.jeanmarie

Hi, I have a problem. I follow these instructions and I still get connected. For my pc (using win 7) it's ok. When I try to connect via my mac (using mac os 10.6.6) it asks me an account and a password before. I try a UNIX account,didn't work.I try windows account,same problem. My linux computer use Ubuntu 11.10. Can you help me please?

jack6666
jack6666

... for these excellent instructions! Solar Driveway Lights|Rope Lights

thursbysoftware
thursbysoftware

For a home or small business, all should work well. For media companies with a lot of FCP, ACS, Avid etc. it's worth noting that the native SMB support isn't that robust and DFS isn't there at all. The problem is the same for storage against Windows Server, NAS or Samba.