Samba is an application that allows a Linux or UNIX host to act as a file server for Windows systems and Windows systems can access UNIX filesystems and printers using their native Windows networking. We'll demonstrate a Linux system mounting a Windows drive and a Windows system mapping a Linux drive in this section. My goal in this section is to give an overview of the setup of Samba and demonstrate a subset of its functionality. In this section we'll use Red Hat Linux software used throughout this book; however, Samba is available for almost all Linux and UNIX variants. Samba provides its file-sharing functionality using Server Message Block (SMB) protocol. SMB runs on top of TCP/IP. In our example in this section, both the Windows system and UNIX system are running TCP/IP and SMB. These provide all of the technology that is required to establish file sharing between the two systems. At the time of this writing Samba contains the functionality just mentioned: file-sharing, printer sharing, and advanced user access control of files. There are many advancements taking place with Samba and other software provided under GNU Public License (GPL) as free software. Because the software is free, many people have access to it and spend time enhancing the software. For this reason, you may find that additional functionality is included in Samba and other such software. There are many enhancements planned for Samba, including an administration tool and other advancements that were not available at the time this chapter was written. There is more information about obtaining Samba and other free software at the end of this section. smb.conf SetupBecause Samba is supplied on the Red Hat Linux CD-ROM, we'll walk through a simple Samba setup using Red Hat Linux. When installing Red Hat Linux, you can select the software packages you wish to load, as you can on most all UNIX variants. If you did not load Samba at the time you originally loaded the operating system, you can use a graphical RPM tool or rpm from the command line to load Samba or any other software. These tools were briefly discussed in the System Administration Chapter 10. The configuration file for Samba is /etc/samba/smb.conf . The smb.conf file has all Samba- related setup information in it. For our simple Samba setup in this chapter we need to have only a few lines in the file setup. We need to have a few Global Settings and Share Definitions in order to achieve our file system sharing between the Windows and Linux systems. The following are three select sections from smb.conf that were modified for our example in this section: # workgroup = NT-Domain-Name or Workgroup-Name workgroup = DEVENV encrypt passwords = yes smb passwd file = /etc/samba/smbpasswd [homes] comment = Home Directories browseable = yes writable = yes valid users = %S create mode = 0664 directory mode = 0775
We made only these three modifications to the smb.conf file; however, next we'll run a Samba utility called testparm . This utility will check our /etc/smb.conf file for errors. This utility produces a very long output which I won't include here, but you'll want to run this and check for any warnings or errors it produces. # testparm smb.conf Load smb config files from smb.conf Processing section "[homes]" Processing section "[printers]" Loaded services file OK. Press enter to see a dump of your service definitions # Global parameters [global] coding system = client code page = 850 code page directory = /usr/share/samba/codepages workgroup = DEVENV netbios name = netbios aliases = netbios scope = server string = Samba Server interfaces = bind interfaces only = No security = USER encrypt passwords = Yes update encrypted = No allow trusted domains = Yes hosts equiv = min passwd length = 5 map to guest = Never null passwords = No obey pam restrictions = Yes password server = smb passwd file = /etc/samba/smbpasswd . . . There were not warnings or errors produced from having run testparm so we'll proceed to the next step. User SetupWe now need to create a user on both the Linux and Windows systems that can be used for our Samba-related work. It may already be that you have suitable users on your system. For the purposes of this demonstration we'll create a user on both systems. On the Linux system we can use the useradd program from the command line or User Manager graphical program ( Programs-System-User Manager ) to add the user. The user will appear in the /etc/passwd file after they have been added. We'll then issue the following command to add the encrypted user passwd to the /etc/samba/smbpasswd file: # smbpasswd -a linuxconnect linuxconnect is the name of the user we created for this example. You can view the smbpasswd file to see the entry for your user. This same user was created on the Windows system. The menu pick Start-Programs-Administrative Tools-Computer Management (Local Users and Groups-Users) was used to create linuxconnect . Samba StartupYou can start Samba daemons every time the system boots or start them at the command line. The following commands show starting the daemons at the command line and then viewing them: # /sbin/service smb start Starting SMB services: [ OK ] Starting NMB services: [ OK ] # ps -ef grep mbd root 10828 1 0 16:59 ? 00:00:00 smbd -D root 10833 1 0 16:59 ? 00:00:00 nmbd -D # We started the daemons with /sbin/service smb start and check to see our two daemons running with ps . Should you make a change to your Samba setup and wish to restart the daemons, you could use /sbin/service smb restart . The smbd server daemon provides the file and print services to SMB clients , such as Windows systems. SMB stands for "Server Message Block" and is defined as a network protocol for sharing files, printers, serial ports, and communications abstractions such as named pipes and mail slots between computers. The nmbd server daemon allows for NetBIOS over IP name service requests over a network, like those produced by SMB/CIFS clients such as Windows systems. We have now performed all of the basic setup required to proceed with mounting disks. Mapping a Windows Drive to a Linux DirectoryNow we can both browse the Linux system from Windows as well as mount a specific drive directory of the Linux system on our Windows system. Figure 15-4 shows the window in which we specify the Linux system and directory we will mount as F: on the Windows system: Figure 15-4. Mapping Linux Drive to F: on Windows
We specified the path of \\linuxdev\linuxconnect to mount on the Windows system drive F: . This is the hostname ( linuxdev ) and the username ( linuxconnect ). The system knows automatically to go to the home directory for linuxconnect and mounts that directory as F: for us on the Windows system, as shown in the Figure 15-5: Figure 15-5. Viewing HP-UX Root Filesystem as F: on Windows
The /home/linuxconnect directory on our Linux system is now fully accessible on the Windows system. We can browse, edit, copy, and perform other tasks on these shared files. We can use net view on our Windows system to see the shared resource of our Linux directory as shown in the following listing: c: net view \linuxdev Shared resources at \linuxdev Samba Server Share name Type Used as Comment ------------------------------------------------------ homes Disk Home Directories linuxconnect Disk F: Home Directories The command completed successfully. This listing shows that F: has our Linux directory mapped to it. Let's now get the overall status of the Samba setup with the smbclient utility on our Linux system, as shown in the following listing: # su - linuxconnect $ smbclient -L linuxdev added interface ip=192.168.1.102 bcast=192.168.1.255 nmask=255.255.255.0 Domain=[DEVENV] OS=[Unix] Server=[Samba 2.2.3a] Sharename Type Comment --------- ---- ------- homes Disk Home Directories IPC$ IPC IPC Service (Samba Server) ADMIN$ Disk IPC Service (Samba Server) linuxconnect Disk Home Directories Server Comment --------- ------- LINUXDEV Samba Server Workgroup Master --------- ------- ATLANTA2 F4457MXP DEVENV LINUXDEV Before issuing the smbclient command we changed user to linuxconnect and then issued the command. This utility produces a useful summary of the Samba setup, including the share linuxconnect we set up, the Samba server for our example, and other useful information. ------------------------------------------------- Keep in mind that Linux, including the Red Hat distribution used in this example, has a high level of security by default upon installation. The firewall setting on the system in our example was set too high for this drive to be mounted in our example. We first had to lower the security level of the firewall setting. Using the /usr/sbin/setup program and selecting Firewall Configuration, we lowered the Security Level to No Firewall, as shown in Figure 15-6: Figure 15-6. setup Program Used to Eliminate Firewall
We used setup to eliminate the firewall in this example. This greatly reduces the overall security of the Linux system, so you have to consider this before making the change. As a result of this selection, files on the system were updated to permit more open access to the system, which gave us the ability to map a network drive to our Linux system, but it also reduced the overall level of security on the system. Mounting a Windows Drive on a Linux SystemThe previous example demonstrated mapping a Linux file system to a Windows drive. This is commonly done since Linux file systems often act as file servers in a Windows environment. We can also get access to a Windows drive on our Linux system for file sharing purposes or to back up a Windows drive to a Linux system. The following commands show mounting the C: drive on our Windows system as the directory /home/linuxconnect/pcdev on our Linux system: # smbmount //F4457MXP/c /home/linuxconnect/pcdev -o username=linuxconnect Password: # # # cd /home/linuxconnect/pcdev # ls 6.1_for_2002_Setup.exe HP phone ~adpttmp I386 PMig01.Log aim95.exe INFONET PMig02.Log AUTOEXEC.BAT IO.SYS PMig03.Log BDE kmd.exe PMig0.Log BOOT.BAK lj527en.exe PMig.Log boot.ini Morpheus-b3d-v2.exe Program Files BOOTLOG.TXT MSDOS.SYS Recycled cmdcons My Music RECYCLER cmldr My Photos RunDelay COMMAND.COM NETPRINTER sdc_install.log comreads.dbg netzero.exe sdc.ok comused.dbg NI setupmpe.exe CONFIG.SYS notworm Support data NTDETECT.COM System Volume Information DMI ntldr temp Documents and Settings OMNIBOOK temp.ps drivers OMNILIB TOUR ENV openmail.log unzipped FDWINW pagefile.sys VERSION.INF hiberfil.sys Perl WINNT # In the smbmount command we specified the name of the Windows system and the path ( /F4457MXP/c ) we wanted to mount on the Linux system. We could have specified any drive or a directory of any drive but we specified the full C: directory. We then specified the mount point on the Linux system of /home/linuxconnect/pcdev and the username of linuxconnect. We were then prompted for the password for this user and given access to the drive. The listing shows that the entire C: drive has been mounted. Now that the entire C: drive is accessible on our Linux system, we can perform any tasks on these files, such as performing a backup of the entire drive or selected files to our Linux system. Figure 15-7 shows a Linux file manager window ( Konqueror ) open showing C: from the Windows system. Figure 15-7. Konqueror Viewing C: on Linux System
Figure 15-7 shows folders on the C: drive of our Windows system displayed in one of the file manager windows on our Linux system. We can traverse this hierarchy freely to view, copy, and work with these files in other ways. We have demonstrated mounts working in both directions. C: on our Windows system was mounted as /home/linuxconnect/pcdev on our Linux system. /home/linuxconnect was mapped to F: on our Windows system. Additional Samba functionality exists, such as print serving, that were not shown in this example. Log FilesLike most UNIX applications, Samba provides extensive logging. The smb.conf file contains a section that allows you to specify the level of Samba logging you wish to take place. The short section below shows that you can have separate log files for each Windows machine that connects, and you can specify the maximum size of the log file: # this tells Samba to use a separate log file for each machine # that connects log file = /var/log/samba/log.%m # Put a capping on the size of the log files (in Kb). max log size = 50 The directory /var/log/samba contains a variety of Samba log files, including the log file for the Windows system used in our examples in this chapter, called f4457mfp2, as shown in the following listing: # ls -l /var/log/samba total 27 -rw-r--r-- 1 root root 0 Jun 15 11:15 f4412bfg.log -rw-r--r-- 1 root root 0 Jun 23 04:03 f4457mxp.log -rw-r--r-- 1 root root 664 Jun 23 04:03 f4457mxp.log.1 -rw-r--r-- 1 root root 0 Jun 21 12:22 linuxdev.log -rw-r--r-- 1 root root 8993 Jun 29 05:01 log.nmbd -rw-r--r-- 1 root root 1918 Jun 29 04:56 log.smbd -rw-r--r-- 1 root root 405 Jun 29 04:56 nmbd.log -rw-r--r-- 1 root root 65 Jun 24 04:03 smbd.log -rw-r--r-- 1 root root 65 Jun 24 04:03 smbd.log.1 -rw-r--r-- 1 root root 3271 Jun 29 05:00 smbmount.log -rw-r--r-- 1 root root 7431 Jun 23 04:03 smbmount.log.1 |