Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Accessing Shares

Samba shares can be accessed by SMB clients on Windows and Linux platforms. Windows access is via Network Neighborhood and Windows Explorer, as well as the net view and net use commands from the DOS prompt. Linux access is via the smbclient and smbmount commands.

Using smbclient on a Linux Client

The smbclient program allows Linux users to access SMB shares on other machines (typically Windows). If you want to access files on other Linux boxes, you can use a variety of methods including FTP, NFS, and the r-commands, such as rcp.

smbclient provides an FTP-like interface that allows you to transfer files with a network share on another computer running an SMB server. Unlike NFS, smbclient does not allow you to mount another share as a local directory. smbmount, which is discussed later in this chapter, provides the capability to mount smb shares.

smbclient provides command-line options to query a server for the shared directories available or to exchange files. For more information on all the command-line options, consult the man page for smbclient. Use the following command to list all available shares on the machine 192.168.100.1:


   $ smbclient -NL 192.168.100.1

Any name resolving to the IP address can be substituted for the IP address. The -N parameter tells smbclient not to query for a password if one isn't needed, and the -L parameter requests the list.

To transfer a file, you must first connect to the Samba server using the following command:


   $ smbclient //192.168.100.1/homes -U tackett

The parameter //192.168.100.1/homes specifies the remote service on the other machine. This is typically either a filesystem directory or a printer. Any name resolving to the IP address can be substituted for the IP address. The -U option enables you to specify the username you want to connect with. There are many additional smbclient command configurations; see the smbclient man page for full details. The smbclient utility prompts you for a password if this account requires one and then places you at this prompt:

smb: 

\ indicates the current working directory.

From this command line, you can issue the commands shown in Table 17.1 to transfer and work with files.

Table 17.1. smbclient Commands

Command Parameters Description
? or help [command] Provides a help message on command or in general if no command is specified.
! [shell command] Executes the specified shell command or drops the user to a shell prompt.
cd [directory] Changes to the specified directory on the server machine (not the local machine). If no directory is specified, smbclient reports the current working directory.
lcd [directory] Changes to the specified directory on the local machine. If no directory is specified, smbclient will report the current working directory on the local machine.
del [files] The specified files on the server are deleted if the user has permission to do so. Files can include wildcard characters.
dir or ls [files] Lists the indicated files. You can also use the command ls to get a list of files.
exit or quit none Exits from the smbclient program.
get [remotefile] [local name] Retrieves the specified remotefile and saves the file on the local server. If local name is specified, the copied file will be saved with this filename rather than the filename on the remote server.
mget [files] Copies all the indicated files, including those matching any wildcards, to the local machine.
md or mkdir [directory] Creates the specified directory on the remote machine.
rd or rmdir [directory] Removes the specified directory on the remote machine.
put [localfile] [remotename] Copies the specified file from the local machine to the server.
mput [files] Copies all the specified files from the local machine to the server.
print [file] Prints the specified file on the remote machine.
queue none Displays all the print jobs queued on the remote server.

You can specify the password on the command line by appending a percent sign to the username followed by the password:


   $ smbclient //192.168.100.1/homes -U tackett%tackettspassword

Although the preceding command is convenient, many versions of UNIX show the password portion of the command in clear text in a ps command. Default Red Hat Linux 7 installations show the password as a string of X characters, but in security-critical environments, or where someone might be looking over your shoulder, it's better to let smbclient prompt for the password and accept it silently.

Mounting Shares on a Linux Client

To make life even easier, the smbmount command enables you to mount a Samba share to a local directory. To experiment with this, create an /mnt/test directory on your local workstation. Now run the following command as user root, or quoted in the tail of an su -c command:

# mount -t smbfs //192.168.100.1/homes /mnt/test -o username=myuid,dmask=777,fmask=777

This command is an smbmount command, even though it looks like an ordinary mount command. The -t smbfs tells the mount command to call smbmount to do the work. The preceding command grants all rights to anyone, via the dmask= and fmask= arguments. These arguments can be tuned to give proper access.

Another syntax is the following:


   # smbmount //192.168.100.1/homes /mnt/test -o username=myuid,dmask=777,fmask=777

This calls smbmount directly, but the syntax using the Linux mount command is preferred.

Assume the command is given on the local workstation, and that workstation already contains a /mnt/test directory. Further assume a Samba server at 192.168.100.1, accessible to the workstation via the network. Note that any name resolving to the IP address can be substituted for the IP address. Running the preceding command on the local machine mounts to local directory /mnt/test the share defined in the [homes] section, logged in as user myuid.

To unmount it, simply run this command as user root, or quoted in the tail of an su -c command:


   # umount /mnt/test

This capability is not limited to the user's home directory. It can be used on any share in smb.conf on the Samba server.

You can also use smbmount to mount shared Windows resources on a Linux computer. The following mounts Windows 98 share menudata on existing Linux directory /mnt/test:


   # mount -t smbfs //wincli/menudata /mnt/test

This must be done as root. You'll be asked for a password. Be sure to input the password of the share, because Windows 9x sharing is share mode, not user mode. To mount NT or Windows 2000 shares, use the -U option followed by a valid username on the Windows computer. That user must have rights to the share. Furthermore, be sure you can resolve the Windows machine by name (that is, WINCLI) in DNS, or the preceding command may fail or hang. Also, be sure that /mnt/test exists, or you'll receive an error message saying Could not resolve mount point /mnt/test.

Share ThisShare This

Informit Network