Sams Teach Yourself Samba in 24 Hours

ContentsIndex

Hour 7: File Sharing

Previous HourNext Hour

Sections in this Chapter:

 

Setting Up a Share

[first-share]

path

comment

browsable

To set up a share, you must add a section for the share to your smb.conf file in the share definitions area. Because Samba shares directories and the files under them, you must first find or create an appropriate directory on your server to share.

Here you are going to create a directory called /home/first-share that you tell Samba to share for you:

mkdir /home/first-share

If you are feeling adventurous, you can use a different name, but you have to make sure you change all the pathnames in what follows, and the examples in this book might be different from what you see.

Next, you add the following to the preceding smb.conf file:

 [first-share]
    comment = My first share
    path = /home/first-share
    browsable = yes

Now that you have added a share to your smb.conf file, you can restart Samba, and (after a while) should be able to see the new share in Network Neighborhood, as shown in Figure 7.4.

Figure 7.4
Network Neighborhood shows your first share!

Great, now you can see a share on your Samba server. What else can you do? Well, before you go looking at the share, you had better put some files in it:

cat > /home/first-share/file-1.txt
Now is the time for all good men
To come to the aid of their country
^D
cat > /home/first-share/file-2.txt
The time has come the walrus said
To talk of many things
^D
todos /home/first-share/file-2.txt

Now that you have put some files in the share on your server, see what your client shows you. Double-click first-share in the Network Neighborhood window, and you see your files, as shown in Figure 7.5.

Figure 7.5
The first two files in your file share.

Now that you can see these files, have a look at them. Double clicking on file-1.txt should produce the display in Figure 7.6.

Figure 7.6
file-1.txt has funny characters in it.

Close that window, and then double-click file-2.txt. You should see what appears in Figure 7.7.

Figure 7.7
file-2.txt looks more normal.

Why do these two files display so differently in Notepad? The problem is a consequence of the different ways in which Windows and UNIX store an end of line in text files. Under UNIX, end-of-line is represented with the newline, or NL, character (octal 012, hex 0x0A), whereas under Windows (and DOS), end-of-line is represented as a carriage return character, or CR (octal 015, hex 0x0C) followed by a newline character. When you created file-2.txt, you explicitly converted it to a DOS format text file (using todos) while leaving file-1.txt as a UNIX-format text file.

Now, although the purpose of each of the lines added to the smb.conf file might be obvious, I'll go through them and explain them in more detail.

[first-share]

This line introduces a new section that is for the share first-share. Each share is introduced as a new section, with its name in square brackets.

comment

This line provides a descriptive comment for the share. It serves to document the share in the smb.conf file and shows up in the Network Neighborhood listing.

path

This line tells Samba which part of the file system to share to clients. You should always specify a directory that exists or a file that is a symbolic link to a directory (see the following).

If the directory does not exist, Windows clients can give weird error messages when trying to access the share. For example,

Cannot access \\EAGLE\first-share: The network name is either
not found on the running network, or is incorrect.

browsable

Strictly speaking, you do not need to specify this entry, as the default is yes. You would normally use browsable only if you do not want clients to see particular shares. For those of you who cannot spell, browsable is a synonym for browseable.

To see the effect of the browsable setting, change it to

browsable = no

in your smb.conf file and restart Samba. Then go back to the FOWLPLAY Network Neighborhood window and double click the server EAGLE. Do you now see the share you have created when the window finally comes up?

Sams Teach Yourself Samba in 24 Hours

ContentsIndex

Hour 7: File Sharing

Previous HourNext Hour

Sections in this Chapter: