11.2. FreeBSD's smbfsFreeBSD, Darwin, and Mac OS X all provide the smbutil and mount_smbfs programs for connecting to SMB/CIFS shares. Neither of the programs is part of Samba; however, we include them to give you a little additional support in case you have BSD-related Unix systems on your network.[*]
11.2.1. smbutilThe smbutil program provides functionality similar to some of the Samba suite's command-line utilities. It can be used to list the shares available on an SMB server or perform NetBIOS name lookups. The first argument given to smbutil is one of a number of subcommands and is usually followed by arguments specific to the subcommand. For example, to list the resources offered by a server, use the view subcommand and enter your server password when prompted: $ smbutil view //elm Password: <enter password> Share Type Comment ------------------------------------------------------------- public disk SS2500 printer Stylus Scan 2500 IPC$ pipe IPC Service (Samba 3.0.22) lizard disk User Home Directories 4 shares listed from 4 available
If you wish to connect to the server with a username that differs from the one you are currently logged in as, you can specify it on the command line by preceding the name of the server with the username and using an at-sign (@) as a separator: $ smbutil view //lizard@elm You can also include the password after the username, using a colon (:) as a separator, to avoid being prompted for it: $ smbutil view //lizard:secret@elm Typing your password in the open like this is strongly discouraged. An alternative is to use smbutil to generate a password hash using the crypt subcommand: $ smbutil crypt secret $$1625a5723293f0710e5faffcfc6 This hash can then be used in place of a clear-text password. However, the encryption is not particularly strong and will foil only the most casual inspection. The only reasonably secure method of providing a password is to be prompted for it. While starting up, smbutil reads the file .nsmbrc in the user's home directory. A list of common configuration parameters is summarized at the end of this section in Table 11-3.
For example, to keep your password in your ~/.nsmbrc file, you can create an entry in the file such as the following: [ELM:LIZARD] password=$$1625a5723293f0710e5faffcfc6 The section heading in brackets specifies the SMB server's NetBIOS name and the username to which the subsequent parameter settings apply. (The hostname and username must be supplied in uppercase characters.) Section headings can also consist of just a hostname or can contain a share name as a third element for specifying parameters applicable to a single share. Finally, if a [default] section is present, the settings in it apply to all connections. The following example .nsmbrc shows some of the other parameters you might use: [default] # NetBIOS name server nbns=192.168.1.74 [ELM] # server IP address addr=192.168.1.46 workgroup=TEST [ELM:LIZARD] password=$$1625a5723293f0710e5faffcfc6 Directives in per-user configurations can be overridden on a systemwide basis by storing directives in the file /etc/nsmb.conf. This method provides you with a means to apply mandatory settings to all users. Directives can be placed in this file using the section and parameter format similar to that of the Samba configuration file. smbutil is somewhat of a hybrid of Samba's smbclient and nmblookup tools. The lookup subcommand returns the IP address associated with a given NetBIOS hostname. A NetBIOS name server can be optionally specified with the -w argument: $ smbutil lookup -w 192.168.1.74 ELM Got response from 192.168.1.74 IP address of ELM: 192.168.1.46 11.2.2. mount_smbfsThe mount_smbfs program performs essentially the same function as mount.cifs on Linux. It mounts an SMB/CIFS share on a directory in the local filesystem. The share can then be accessed just like any other directory. The command synopsis for mount_smbfs is: mount_smbfs [options] Share-UNC mount-point where Share-UNC is of the form: //[workgroup;][username[:password]@]server[/share] For example: $ mount_smbfs //TEST;lizard:$$1625a5723293f0710e5faffcfc6@elm/lizard\ /smb/lizard A list of common configuration parameters and command-line options is provided in Table 11-3. The ownership and permissions of the mount point determine the default ownership and permissions for files and directories in the mounted share. These can be modified with command-line arguments, like this: $ mount_smbfs -u lizard -g admin -f 0750 -d 0755 \ //lizard@elm/lizard /smb/lizard In this example, the files and directories in the mounted share are owned by the user lizard and the group admin, with files and directories having permissions 750 and 755, respectively. As usual, the permissions are specified in the octal format used by the Unix chmod command. The mount_smbfs command also makes use of settings in /etc/nsmb.conf and ~/.nsmbrc, as described earlier. |