Samba Clients


Now that all your Samba shares are set up, you can access them from one of the client systems (Client02). Be aware that you need to install the client Samba packages before you can connect to any Samba shares.

Step 1. Install the client packages:

# yum install -y samba-client samba-common

Step 2. Verify that the install was successful:

# rpm -qa | grep samba
samba-client-3.5.4-68.el6.x86_64
samba-winbind-clients-3.5.4-68.el6.x86_64
samba-common-3.5.4-68.el6.x86_64

Step 3. Create a local directory where you will mount your Samba share.

For this example, make it the same as the Samba share directory to keep things simple:

# mkdir /opt/company_data

Using the smbclient command, you can now mount the Samba share.

Syntax:

smbclient [options]

Options:

参数 作用
-L Lists Samba shares
-U Defines the user to connect with
-P Defines the password to connect with
-A Gets credentials from a file

Step 4. List the Samba shares on the RHEL01 Samba server:

# smbclient -L 172.168.1.1 -U user01%<you password here>
Domain=[RHEL01] OS=[Unix] Server=[Samba 3.0.33-3.29.el5_5.1]
Sharename Type Comment
--------- ---- -------
company_data Disk Directory for all employees
within the
company
IPC$ IPC IPC Service (My Samba Server)
Domain=[INET] OS=[Unix] Server=[Samba 3.5.4-68.el6]
Server Comment
--------- -------
Workgroup Master
--------- -------
INET RHEL01

You can see here that the share named company_data is available for access. Recall from Chapter 4 that the mount command allows you to connect additional resources to the file system hierarchy. You can use the mount command here with the cifs option to mount the Samba share.

Step 5. Mount the remote Samba share:

# mount.cifs //172.168.1.1/company_data /opt/test -o
username=user01,password=<password>

You can verify that the mount worked successfully by using the smbstatus command.

Syntax:

smbstatus [options]

Options:

参数 作用
-p Shows processes only
-v Provides verbose output
-S Shows shares only
-L Shows locks only

Step 6. Verify the mount was successful:

# smbstatus
Samba version 3.5.4-68.el6
PID Username Group Machine
-------------------------------------------------------------------
3378 user01 user01 172.168.1.20 (172.168.1.20)
Service pid machine Connected at
-------------------------------------------------------
company_data 3378 172.168.1.20 Tue Oct 12 16:06:47 2010
No locked files

自动挂载

So far, you are doing well with the client being able to connect to the Samba server. You need to know that any share that is mounted without being added to the /etc/fstab file will be unmounted after the system is rebooted. To remedy this situation, you can create an entry in the /etc/fstab file.

Step 1. Create an entry in the /etc/fstab file:

//172.168.1.1/company_data /opt/test cifs user=user01,pass=
<password> 0 0

Can anyone find a problem with this entry? The problem here is that the username and password are exposed in clear-text for anyone to see. Another way that you can create an entry in the /etc/fstab file without exposing credentials is to put the credentials inside a file to be refer- enced from the /etc/fstab file.

Step 2. Add the credentials that you’d like to use to a file:

# echo “username=user01” > /etc/samba/smbcred
# echo “password=password” >> /etc/samba/smbcred

TIP

Make sure to set the permissions of the /etc/samba/smbcred file properly.

Step 3. Update the entry in the /etc/fstab file to reflect the changes to how the credentials are read:

//172.168.1.1/company_data /opt/test cifs
credentials=/etc/samba/smbcred 0 0

You can use the umount.cifs command to unmount the Samba share and reboot the system to make sure that the share mounts correctly when the system reboots.


Review Questions

  1. What are the two types of back-end authentication mechanisms discussed in this chapter?
  2. When you’re creating a share, there is no option to make it browseable. True or False?
  3. What does the testparm command do?
  4. What command is used to create a user for Samba?
  5. What command can you use to view mounted Samba shares?
  6. Samba servers can serve files only to users. True or False?

Answers to the Review Questions

  1. This chapter described tdbsm and smbpasswd back-end authentication.
  2. False. The browseable option is available for each share.
  3. The testparm command allows you to check for syntax errors in the /etc/samba/smb.conf file.
  4. The smbpasswd command is used to create Samba users.
  5. The smbstatus command shows you currently mounted Samba resources.
  6. False. Samba servers can serve both files and printers to users.

results matching ""

    No results matching ""