File and Print Sharing

Discussion in 'Linux Basics' started by LinuxDotOrg, Jul 9, 2013.

  1. LinuxDotOrg

    LinuxDotOrg Administrator

    Messages:
    34
    Likes Received:
    66
    Trophy Points:
    8
    File and print sharing

    When the PC first showed up around 1980, most of them were single-user devices, unconnected and basically on their own. Now, it's more than likely that the PC you use at work is connected to the other PCs around you. They are in turn connected to the PCs in the whole building. Which are more than likely connected to the internet and therefore the world. We've made the world a lot smaller, but there are pros and cons of this interconnectedness. Apart from information, we also may be sharing other things. The RIAA fears that we may be sharing music illegally. We may be sharing viruses, though this is unlikely on my end because I use Linux. But as an IBM engineer once said, if you want total security, shut the machine off and lock it in the closet. That's not practical, obviously. But we're going to look at taking advantage of the positive side of sharing. If you happen to have Windows machines in your office, the truth is that you don't really need a Windows server to share Windows files and printers. There's a tool that runs under Linux that can do it too. It's called Samba.

    Samba


    As with other major, popular Open Source tools we've seen here, Samba comes with most mainstream Linuxdistributions. It will be installed automatically if you request it and some basic configuration will be done for you. Again, I will reiterate my standard disclaimer. This section is considered a basic introduction to Samba. I just saw that one of Open Source luminary Bruce Perens' guides which is dedicated to Samba comes in at just under 700 pages, so you can imagine that there is a lot of ways to configure and use Samba. We'll try to deal with some of the more common configuration options here.

    User accounts for Samba

    If you're thinking about letting people using Windows machines store files on your Linux server, you'll need to create user accounts on the Linux machine. If you've gotten this far in the lessons, we'll assume that you know how to do this and skip the how-to part.

    Next, you'll need to give them the same Samba password. There is a program to do this which is appropriately namedsmbpasswd. Let's say you wanted to add a user bsmith. You would type the following:
    Code:
    smbpasswd -a bsmith
    
    This will ask you to type a password twice, as is the Unix custom. You should give the users the same password that they have on the Windows machine if you want the little Network Neighborhood icon to let them in "automagically".

    Now, when user bsmith logs in to his Windows machine and clicks on the network icon, he should see our Linux machine running Samba. When he clicks on the machine's icon, he should then be able to see an icon for his Linux user directory. He can then begin leaving his files there - that is - if Samba is correctly configured. Let's look at Samba's configurationfile, smb.conf.

    smb.conf

    The main Samba configuration file can normally be found in /etc/samba/ and it's called smb.conf. This file is placed here when you install Samba. The developers of Samba have done a great job commenting it to explain to you what every line means. The first one we'll need to do something with is this one:

    Code:
    workgroup = utopia
    
    This is where you need to enter the name of your Windows workgroup. That's pretty self-explanatory. Let's move on to the next.

    Code:
    load printers = yes
     
    printing = cups
     
    printcap name = cups
    
    These line are there to provide print services. CUPS (or Common Unix Printing System) is an extremely reliable and well supported protocol. This must installed and running in order for this to work, of course.

    Now we need to make additions and modifications in our printers section so that Windows machines will use CUPS to print. Modify your [printer] section to this:
    Code:
    [printers]
     
    path = /var/spool/samba
     
    browsable = no
     
    public = yes
     
    guest ok = yes
     
    writable = no
     
    printable = yes
     
    printer admin = root
    And add this section:

    Code:
    [print$]
     
    path = /etc/samba/drivers
     
    browsable = yes
     
    guest ok = no
     
    read only = yes
     
    write list = root
    
    We now need to have CUPS put all of the drivers it has at the disposal of Samba. The CUPS software comes with a tool to do this. It's called cupsaddsmb. Type:
    Code:
    cupsaddsmb -a -U root
    This will add all CUPS printer drivers to your Samba setup. Just a word of caution. Printing, in my experience, is a tricky thing. You may have the most ultra-new printer on the block and it may not work right away. You need to be fairly certain before hand that your printer has had some time on the market for the appropriate drivers to have been made available. Most printers from well-known manufacturers should work.

    Once print services have been set up, we need to look at the file sharing configuration options. First, we need to look at how the /home directories of users are going to be handled.

    Code:
    [homes]
     
    comment = Home Directories
     
    browseable = no
     
    writable = yes
     
    create mask = 0700
     
    directory mask = 0700
    This will insure that other people will not be able to look around (browse) files and won't be able to create and/or overwrite files or create directories (notice the 00 given to group and others). Only the owner of the directory will be able to write to it.

    We may want to configure a particular directory on our Linux box to contain files for everybody to see. For example, if your office is using Hylafax to send and receive faxes you could set up a Samba share so everyone can automatically look at received faxes.


    Code:
    [Fax_Rec]
     
    comment = Incoming Faxes
     
    browseable = yes
     
    writable = no
     
    path = /var/spool/hylafax/recvq
     
    public = yes
    
    With a TIFF viewer, people at Windows workstations will be able to see the faxes that come in to the office.

    Samba will also give you the ability to share CD drives as well. All you have to do is uncomment the lines pertaining to this in the smb.conf file and add a line like the following to your /etc/fstab
    Code:
    /dev/hdX  /mnt/cdrom  iso9660 defaults,noauto,ro,user  0 0
    where 'X' is the letter corresponding to your IDE CD ROM drive.


    Plenty of documentation

    This shows how versatile Linux is. You can make a Windows NT out of a Linux box running Samba if, like many organizations, you have a number of Windows machines. Again, we have just scratched the surface of what Samba is capable of. Have a look at the documentation that comes with Samba and you'll find a wealth of information about it.

Share This Page