Accessing CIFS Shares Via Samba on the CLI

6940511-a-cartoon-toilet-paper-roll-smiling-and-happyHey I just wrote a giant post on how to configure Samba on RHEL 6. You can see it here. However I wanted to take a minute to review how to access and mount CIFS shares in RHEL while I was at it.

Using Sambaclient Command

The sambaclient command in installed via the samba-client rpm and in my case can be installed via the following command

# yum -y install samba-client.x86_64

Using smbclient you can access a CIFS share via the command line in a fasion similar to ftp.

The example below shows how to list the shares availible on a particular host, in this example I am using localhost. /samba is my samba share

# smbclient -L //localhost/samba -U myuser
Enter myuser's password:
Domain=[WORKGROUP1] OS=[Unix] Server=[Samba 3.5.11-79.fc14]

        Sharename       Type      Comment
        ———       —-      ——-
        samba           Disk     
        IPC$            IPC       IPC Service (Samba Server Version 3.5.11-79.fc14)
        OfficeJet-V40xi Printer   Hewlett-Packard OfficeJet V40xi
        OfficeJet-V40xi-Fax Printer   HP Fax
        myuser          Disk      Home Directories
Domain=[WORKGROUP1] OS=[Unix] Server=[Samba 3.5.11-79.fc14]

To access a share, drop the -L from the command. You should be able to browse this way.

# smbclient //localhost/samba -U myuser
Enter myuser's password:
Domain=[WORKGROUP1] OS=[Unix] Server=[Samba 3.5.11-79.fc14]
smb: \> ls
  .                                   D        0  Wed Aug  8 12:08:22 2012
  ..                                  D        0  Wed Aug  8 11:10:01 2012
  hosts                               A      106  Wed Aug  8 12:08:22 2012
  testing                             D        0  Wed Aug  8 12:08:03 2012

 43860 blocks of size 2097152. 36269 blocks available

Manually Mounting a Share

First off you can do this via the cli with the following command. Where "myuser" is the user name.

# mount -t cifs user=myuser //localhost/samba /mnt

Or you can do this by adding the following to /etc/fstab. This will ensure that the filesystem will mount at boot. In the example below you are creating a file to house a valid samba user and password.

//localhost/samba       /mnt                    cifs credentials=/etc/sambacreds 0 0

The file that I created, sambacreds looks like this.

user=myuser
password=mypassword

Now mount -a to mount your samba share.

One thought on “Accessing CIFS Shares Via Samba on the CLI

  1. Hi, very handy tutorials!
    on my setup this command works:
    # smbclient -L //localhost/samba -U myuser
    but when I drop the -L I get:
    tree connect failed: NT_STATUS_BAD_NETWORK_NAME
    Any ideas?
    Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.