11.11. Connecting Linux Clients to a Samba Domain with Command-Line Programs

Your shiny new Samba domain controller is in service and ready to rock. Your Windows clients are successfully logging in and finding shares just like they're supposed to. How do your Linux PCs join the party using command-line utilities?

These command-line tools are for browsing, logging in, and mounting Samba shares:

Linux does not see domains the same way that Windows does, which is no surprise because the domain structure is a Windows convention. Linux sees filesystems that it has either permission to access or no permission to access. Unlike Windows, which can either log in to a domain or log in locally, but not both, Linux users log in first to their local systems in the normal fashion, then log in to domain shares as needed. Domain shares can be configured to auto-mount in /etc/fstab, just like any other filesystem.

To browse the network and see all the domains, servers, and shares with smbtree, run it with the -N (no password) switch. This will not show nonbrowseable shares,

	$ smbtree -N
	REDDOMAIN
	        \\STINKPAD                       thinkpad r32
	        \\SAMBA11                        Samba PDC
	                \\SAMBA11\HP6L                   HP6L b&w laser printer
	                \\SAMBA11\ADMIN$                 IPC Service (Samba PDC)
	                \\SAMBA11\IPC$                   IPC Service (Samba PDC)
	                \\SAMBA11\share1                 testfiles

You may also browse by either hostname, IP address, or NetBIOS name. In this example, windbag is the hostname, and samba11 is the NetBIOS name as specified in smb.conf:

	$ smbtree -N windbag
	$ smbtree -N samba11

But not the domain name, because the domain name is not a resolvable name.

You may see nonbrowseable shares that are accessible to you by using your username and password:

	$ smbtree -U foober
	Password:
	REDDOMAIN
	        \\STINKPAD                     thinkpad r32
	                \\STINKPAD\C$                  Default share
	                \\STINKPAD\ADMIN$              Remote Admin
	                \\STINKPAD\F$                  Default share
	                \\STINKPAD\print$              Printer Drivers
	                \\STINKPAD\SharedDocs
	                \\STINKPAD\IPC$                Remote IPC
	        \\SAMBA11                      Samba PDC
	                \\SAMBA11\foober               Home Directories
	                \\SAMBA11\HP6L                 HP6L
	                \\SAMBA11\ADMIN$               IPC Service (Samba PDC)
	                \\SAMBA11\IPC$                 IPC Service (Samba PDC)
	                \\SAMBA11\share1               testfiles

When you see the share you want, mount the share on your system with smbmount, using a directory already created for this purpose, and mind your slashes. In this example, user foober mounts his Samba home directory in the local directory samba:

	$ mkdir samba
	$ smbmount //samba11/foober samba
	$ password:

The smbumount command unmounts the share:

	$ smbumount samba

You may use smbclient to access file shares without having to mount the shares. Instead, smbclient uses FTP-like commands to transfer files. This command shows you how to browse the network. You must specify the hostname or NetBIOS name; this shows the hostname:

	$ smbclient -N -L windbag
	Anonymous login successful
	Domain=[REDDOMAIN] OS=[Unix] Server=[Samba 3.0.10-Debian]

	        Sharename       Type      Comment
	        ---------       ----      -------
	        share1          Disk      testfiles
	        IPC$            IPC       IPC Service (Samba PDC)
	        ADMIN$          IPC       IPC Service (Samba PDC)
	        HP6L            Printer   HP6L
	Anonymous login successful
	Domain=[REDDOMAIN] OS=[Unix] Server=[Samba 3.0.10-Debian]

	        Server               Comment
	        ---------            -------
	        SAMBA11              Samba PDC

	        Workgroup            Master
	        ---------            -------
	        REDDOMAIN            SAMBA11

You can find your home directory by browsing with your login:

	$ smbclient -L samba11 -U carla
	Password:
	Domain=[REDDOMAIN] OS=[Unix] Server=[Samba 3.0.10-Debian]

	        Sharename       Type      Comment
	        ---------       ----      -------
	        share1          Disk      testfiles
	        IPC$            IPC       IPC Service (Samba PDC)
	        ADMIN$          IPC       IPC Service (Samba PDC)
	        HP6L            Printer   HP6L
	        carla           Disk      Home Directories
	...

Use this command to connect to your home share:

	$ smbclient -U carla //samba11/carla
	Password:
	Domain=[REDDOMAIN] OS=[Unix] Server=[Samba 3.0.10-Debian]
	smb: \>

When you are at the smb:\> prompt, type ? to show a commands list:

	smb: \> ?
	?              altname      archive      blocksize      cancel
	case_sensitive cd           chmod        chown          del
	dir            du           exit         get            hardlink
	help           history      lcd          link           lowercase
	...

See? Same old familiar Linux commands. The following commands list files, then transfer the foo directory from the server to the local working directory, and renames it to foo-copy:

	smb: \> ls
	smb: \> get foo foo-copy
	getting file \foo of size 2131 as foo-copy (1040.5 kb/s) (average 1040.5 kb/s)
	smb: \>

Uploading files to the Samba share is done with the old familiar put command:

	smb: \> put foo-copy
	putting file foo-copy as \foo-copy (0.0 kb/s) (average 0.0 kb/s)

To close your connection to the share:

	smb: \> quit

The smbmount and smbumount commands call smbmnt. If you run into permissions problems, such as "smbmnt must be installed suid root for direct user mounts," make smbmnt SUID with chmod:

	# chmod +s /usr/bin/smbmnt

If you are nervous about using SUID, set up sudo for authorized smbmnt users.

  • Chapter 8, "Managing Users and Groups," in Linux Cookbook, by Carla Schroder (O'Reilly) to learn how to configure sudo

  • man 8 smbmount

  • man 8 smbumount

  • man 1 smbtree

  • man 1 smbclient