14.6 Using the Samba Client

14.6 Using the Samba Client

Samba comes with a program named smbclient that can print to and access remote Windows shares. This program comes in handy when you are in an environment where you must interact with Windows servers that offer no Unix-friendly means of communication.

To get started with smbclient , use the -L option to get a list of shares from a remote server named SERVER :

 smbclient -L -U  username SERVER  

You do not need -U username if your Linux username is the same as your username on SERVER .

After running this command, smbclient asks for a password. If you want to try to access a share as a guest, you can press ENTER; otherwise , enter your password on SERVER .

Upon success, you should get a share list like this:

 Sharename     Type      Comment          ---------     ----      -------          Software      Disk      Software distribution          Scratch       Disk      Scratch space          IPC$          IPC       IPC Service          ADMIN$        IPC       IPC Service          Printer1      Printer   Printer in room 231A          Printer2      Printer   Printer in basement 

Look at the Type field to make sense of each share. You should only pay attention to the Disk and Printer shares (the IPC shares are for remote management). In this list, there are two disk shares and two printer shares. You can use the name in the Sharename column to access the share.

14.6.1 Accessing Files

If you need only casual access to files in a disk share, use the following command (again, you can omit the -U username if your Linux username matches your username on the server):

 smbclient -U  username  '\  SERVER  \  sharename'  

Upon success, you will get a prompt like this:

 smb: \> 

In this file transfer mode, smbclient is similar to the Unix ftp ; you can run these commands:

  • get file Copies file from the remote server to the current local directory.

  • put file Copies file from the local machine to the remote server.

  • cd dir Changes the directory on the remote server to dir .

  • lcd localdir Changes the current local directory to localdir .

  • pwd Prints the current directory on the remote server, including the server and share names .

  • ! command Runs command on the local host. Two particularly handy commands are !pwd and !ls to determine directory and file status on the local side.

  • help Shows a full list of commands.

Using the SMB Filesystem

If you need frequent access to files on a Windows server, you can attach the share directly to your system with the smbmount command:

 smbmount '\  SERVER  \  sharename  \' -c 'mount  mountpoint'  -U  username  -P  password  

To use this command, you must have the smbfs kernel driver loaded as a module or directly compiled into the kernel. In addition, the rest of the Samba programs should be in your path . By default, a Samba installation built from source code does not include the smbmount command. You must specify --with-smbmount when running the Samba configure script to create these extra programs.

14.6.2 Printing to a Windows Share

The easiest way to print to a Windows SMB share is through CUPS. Follow these steps to get a printer working:

  1. Put the CUPS SMB backend in place. Find the smbspool program in your Samba distribution, and then create a symbolic link named smb in the backend directory to smbspool , like this:

     ln -s  smbspool_path  /smbspool  cups_prefix  /lib/cups/backend/smb 
  2. Restart CUPS.

  3. Run lpinfo -v to confirm that the SMB spooler is in the available backends . You should see this in the output:

     network smb 
  4. Add a new printer as outlined in Chapter 12. If you don't need a password to access the printer, use the following as the printer device path (notice that the backslashes are forward slashes in CUPS):

     smb://  SERVER  /  sharename  

    If you need a username and password, add them to the front of the server:

     smb://  username  :  password  @  SERVER  /  sharename  

    If your target printer is in a different Windows workgroup, you can specify the workgroup in the first part of the name:

     smb://  username  :  password  @  WORKGROUP  /  SERVER  /  sharename  

Sending Files Directly to a Printer Share

If you have a file that is suitable for a printer (such as a PostScript file that you want to send to a PostScript printer), you can send it directly to the printer share with this smbclient variant:

 smbclient '\  SERVER  \  sharename'  -U  username  -P <  file  

This command is particularly useful when testing and troubleshooting printers. Working with CUPS and Samba simultaneously can be difficult, so if you find yourself running into trouble when trying to access a printer on a Windows system, try going through these steps:

  1. Use the Windows system to print a test document to a file, then transfer file to your Linux system.

  2. Run the command in the preceding example to attempt to print the test file .

  3. If the file does not print, you have a problem on the Samba side. Otherwise, the problem lies with CUPS.

How Linux Works
How Linux Works: What Every Superuser Should Know
ISBN: 1593270356
EAN: 2147483647
Year: 2004
Pages: 189
Authors: Brian Ward

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net