Previous Section
 < Day Day Up > 
Next Section


Accessing Samba Services with Clients

Client systems connected to the SMB network can access the shared services provided by the Samba server. Windows clients should be able to access shared directories and services automatically through the Network Neighborhood and the Entire Network icons on a Windows desktop. For other Linux systems connected to the same network, Samba services can be accessed using special Samba client programs. With smbclient, a local Linux system can connect to a shared directory on the Samba server and transfer files, as well as run shell programs. With smbmount, directories on the Samba server can be mounted to local directories on the Linux client.

Note 

Several Samba browser clients are available for GNOME and KDE. For KDE, you can use Komba2 (downloadable from apps.kde.com). For GNOME, you can use Gnomba.

smbclient

The smbclient utility operates like FTP to access systems using the SMB protocols. Whereas with an FTP client you can access other FTP servers or Unix systems, with smbclient you can access SMB-shared services, either on the Samba server or on Windows systems. Many smbclient commands are similar to FTP, such as mget to transfer a file or del to delete a file. The smbclient program has several options for querying a remote system, as well as connecting to it. See the smbclient Man page for a complete list of options and commands. The smbclient program takes as its argument a server name and the service you want to access on that server. A double slash precedes the server name, and a single slash separates it from the service. The service can be any shared resource, such as a directory or a printer. The server name is its NetBIOS name, which may or may not be the same as its IP name. For example, to specify the myreports shared directory on the server named turtle.mytrek.com, use //turtle.mytrek.com/myreports. If you must specify a pathname, use backslashes for Windows files and forward slashes for Unix/Linux files:

//server-name/service

You can also supply the password for accessing the service. Enter it as an argument following the service name. If you do not supply the password, you are prompted to enter it.

Note 

You can also use Nautilus (GNOME file manager) to access Samba shares. Use the smb: protocol, as in smb://lizard/windata. Entering just smb: will display all Samba shares.

Accessing Shares with smblcient

You can then add several options to access shares, such as the remote username or the list of services available. With the -I option, you can specify the system using its IP address. You use the -U option and a login name for the remote login name you want to use on the remote system. Attach % with the password if a password is required. With the -L option, you can obtain a list of the services provided on a server, such as shared directories or printers. The following command will list the shares available on the host turtle.mytrek.com:

smbclient -L turtle.mytrek.com

To access a particular directory on a remote system, enter the directory as an argument to the smbclient command, followed by any options. For Windows files, you use backslashes for the pathnames, and for Unix/Linux files you use forward slashes. Once connected, an smb prompt is displayed and you can use smbclient commands such as get and put to transfer files. The quit or exit commands quit the smbclient program. In the following example, smbclient accesses the directory myreports on the turtle.mytrek.com system, using the dylan login name:

smbclient //turtle.mytrek.com/myreports -I 192.168.0.1 -U dylan

In most cases, you can simply use the server name to reference the server, as shown here:

smbclient //turtle.mytrek.com/myreports -U dylan

If you are accessing the home directory of a particular account on the Samba server, you can simply specify the homes service. In the next example, the user accesses the home directory of the aleina account on the Samba server, after being prompted to enter that account's password:

smbclient //turtle.mytrek.com/homes -U aleina

You can also use smbclient to access shared resources located on Windows clients. Specify the computer name of the Windows client along with its shared folder. In the next example, the user accesses the windata folder on the Windows client named lizard. The folder is configured to allow access by anyone, so the user just presses the ENTER key at the password prompt.

$ smbclient //lizard/windata
added interface ip=192.168.0.2 bcast=192.168.0.255 nmask=255.255.255.0
Got a positive name query response from 192.168.0.3 ( 192.168.0.3 )
Password:
Domain=[WORKGROUP] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \> ls
  .    D    0  Sat Sep  7 17:29:19 2002
  ..   D    0  Sat Sep  7 17:29:19 2002
  hi   A    10  Sat Sep  7 17:29:27 2002
  mynewdoc.doc   A     0  Sat Sep  7 16:59:13 2002
     39997 blocks of size 1048576. 39930 blocks available
smb: \> mget hi
Get file hi? y
getting file hi of size 10 as hi (1.22069 kb/s) (average 1.2207 kb/s)
smb: \> quit

smbclient Commands

Once logged in, you can execute smbclient commands to manage files and change directories. Shell commands can be executed with the ! operator. To transfer files, you can use the mget and mput commands, much as they are used in the FTP program. The recurse command enables you to turn on recursion to copy whole subdirectories at a time. You can use file- matching operators, referred to here as masks, to select a certain collection of files. The file-matching (mask) operators are *, [], and ? (see Chapter 8). The default mask is *, which matches everything. The following example uses mget to copy all files with a .c suffix, as in myprog.c:

smb> mget *.c

During transfers, you can have smbclient either prompt you for each individual file or simply transfer all the selected ones. The prompt command toggles this file prompting on and off.

To access a particular printer on a remote system, enter the printer name as an argument to the smbclient command, followed by any options. In the following example, smbclient accesses the myepson printer on the turtle.mytrek.com system, using the dylan login name:

smbclient //turtle.mytrek.com/myepson -U dylan

Once connected, an SMB prompt is displayed and you can use smbclient commands such as print to print files and printmode to specify graphics or text. In the next example, the user prints a file called myfile, after having accessed the myepson printer on turtle.mytrek.com:

smb> print myfile

smbmount

With the smbmount command, a Linux or Unix client can mount a shared directory onto its local system. The syntax for the smbmount command is similar to that for the smbclient command, with many corresponding options. The smbmount command takes as its arguments the Samba server and shared directory, followed by the local directory where you want to mount the directory. The following example mounts the myreports directory onto the /mnt/myreps directory on the local system:

smbmount //turtle.mytrek.com/myreports /mnt/myreps -U dylan

To unmount the directory, use the smbumount command with the local directory name, as shown here:

smbumount /mnt/myreps

To mount the home directory of a particular user on the server, specify the homes service and the user's login name. The following example mounts the home directory of the user larisa to the /home/chris/larisastuff directory on the local system:

smbmount //turtle.mytrek.com/homes /home/chris/larisastuff -U larisa

You can also use smbmount to mount shared folders on Windows clients. Just specify the computer name of the Windows client along with its folder. If the folder name contains spaces, enclose it in single quotes. In the following example, the user mounts the windata folder on lizard as the /mylinux directory. For a folder with access to anyone, just press ENTER at the password prompt.

$ smbmount //lizard/windata  /mylinux
Password:
$ ls /mylinux
_hi_mynewdoc.doc_myreport.txt

To unmount the shared folder when you are finished with it, use the smbumount command.

smbumount /mylinux

Instead of using smbmount explicitly, you can use the mount command with the file system type smbfs. mount will then run the /sbin/mount.smbfs command, which will invoke smbclient to mount the file system:

mount -t smbfs //lizard/windata  /mylinux

You could also specify a username and password as options, if user-level access is required:

mount -t smbfs -o username=chris passwd=mypass //lizard/windata /mylinux

You can also use the smbfs type in an /etc/fstab entry to have a Samba file system mounted automatically:

//lizard/windata /mylinux smbfs defaults 0 0

Sharing Windows Directories and Printers with Samba Clients

To manage directory shares, open the Computer Management tool in the Administrative window in the Control Panel. Click Shared Folders and there you can see the Shares, Sessions, and Open folders. To add a new share, click the Shares folder and then click the Action menu and select New File Share. The Sessions and Open folders' Action menus let you disconnect active sessions and folders.

To allow share-level open access by users on other clients or on the Samba server, be sure to enable the guest user on your Windows client. It is not enabled by default. Access the Users and Passwords tool in the Control Panel to set up the guest user. Guest access is particularly important for providing access to a printer connected to a Windows client. The Linux system that wants to access a printer on a Windows system will configure the printer on its own system as a remote Samba printer. The user normally entered to access the printer is guest. For the Linux system to access the Windows printer, that Windows system has to have a guest user.

Sharing Windows Directories

To share a directory, right-click the directory and select Sharing from the pop-up menu (Sharing And Security on Windows XP). Click Share This Folder and then enter the share name, the name by which the directory will be known by Samba. You can specify whether you want to allow others to change files on the share. You can also specify a user limit (maximum allowed is the default). You can further click the Permissions button to control access by users. Here, you can specify which users will have access, as well as the type of access. For example, you could allow only read access to the directory.

Sharing Windows Printers

To share a printer, locate the printer in the Printers window and right-click it, selecting the Sharing As option. This opens the Sharing panel, where you can click the Shared As button and enter the name under which the printer will be known by other hosts. For example, on the Windows client named lizard, to have a printer called Epson Stylus Color shared as myepson, the Sharing panel for this printer would have the Shared As button selected and the name myepson entered. Then when the user double-clicks the lizard icon in the Computers Near Me window, the printer icon labeled myepson will appear.

For a Linux system to use this printer, it will have to be first configured as a remote Windows printer on that Linux system. For printers using the LPRng print server, you can do this easily with redhat-config-printer (Printing on the System Settings menu and window), and for printers using the CUPS print server, you use the CUPS Print Configuration tool (Extra System Tools menu).

To configure your remote printer, you give the printer a name by which it is known on your Linux system, the Windows client computer name, the name of the printer as it is accessed on the Windows client, along with the username for access (usually guest). Once configured, your printing commands can access it using just the printer name, as they would any other printer. For example, the myepson printer installed on the Windows client has to also be installed for CUPS on the Linux system operating as the Samba server. For the CUPS print server, you can use redhat-config-printer to configure your Windows printer. You can give the printer the same name, if you wish, and then in the Queue Type panel select Windows Printer (SMB). For the Share, you enter //lizard/myepson; for User, enter guest; and for Workgroup, enter the Windows client's workgroup (usually WORKGROUP).

For the CUPS print server, you can also use the CUPS Print Configuration tool and add the printer. For device, select Windows Printer via Samba. For the device URI, enter the share name with the smb: protocol, smb://lizard/myepson. Also, to enable CUPS to use Samba, you need to link the samba spool directory to the CUPS smb directory.

ln -s /usr/bin/smbspool   /usr/lib/cups/backend/smb

Once it is installed, you can restart the CUPS server. Then an lpr command can access the remote Windows printer directly. The next example prints the mydoc file on the Windows client's Epson printer.

lpr -P myepson mydoc

Windows Clients

To access Samba resources from a Windows system, you will need to make sure that your Windows system has enabled TCP/IP networking. This may already be the case if your Windows client is connected to a Microsoft network. If you need to connect a Windows system directly to a TCP/IP network that your Linux Samba server is running on, you should check that TCP/IP networking is enabled on that Windows system. This involves making sure that the Microsoft Network client and the TCP/IP protocol are installed, and that your network interface card (NIC adapter) is configured to use TCP/IP. The procedures differ slightly on Windows 2000 and XP, and Windows 95, 98, and ME.

Once connected, your Samba shares and printers will appear in the Windows network window. If you are going to use a share frequently, you can assign it a disk label. Right-click the share and select Map Network Drive, and select the drive label you want to use. On XP, you can further select whether you want the drive automatically mounted when you log in. Follow the instructions on your particular Windows system for accessing remote shared resources such as printers and directories.



Previous Section
 < Day Day Up > 
Next Section
This HTML Help has been published using the chm2web software.