Accessing Samba Shares From an Oracle Linux Client

To access a Samba share from an Oracle Linux host, install the following packages:

  • samba-client

    Installing the samba-client package gives you the smbclient utility that provides SFTP-like commands to access Samba shares. For example, smbclient provides a get command for downloading a file from a remote Samba share, and a put command for uploading a file.

  • cifs-utils

    Installing the cifs-utils package lets you mount a Samba share.

Using smbclient Commands

The following steps give a brief overview of how you might use the smbclient commands:

  1. Log onto a share example_samba_share hosted on server example_samba_server using account EXAMPLE.COM/user1:

    sudo smbclient -U "EXAMPLE.COM\user1" //example_samba_server/example_samba_share
  2. Change to directory location /directory1/ :

    smb: \> cd /directory1/ 
  3. Download file ExampleFile.txt:

    smb: \directory1\> get ExampleFile.txt
  4. End the session:

    smb: \directory1\> exit

For more information, see the smbclient(1) manual page.

Mounting a Samba Share

The cifs-utils package provides tools for mounting Samba shares using CIFS and the SMBv3 protocols.

Note:

We recommend using SMBv3 instead of CIFS for improved performance and security.

The following steps describe how to mount a Samba share.

  1. Create a directory to mount the share.

    Create an empty directory in which to mount the share. For example:

    sudo mkdir /mnt/smb-share
  2. Create a credentials file.

    The credentials file lets the user access the share without being prompted for a password. The name of the file is unimportant, but it's a good idea to prefix it by a period to hide it from general view (for example, .credentials). The file must contain the following information:

    username=username
    password=password
    domain=EXAMPLE.COM

    Note:

    The password is the password created for this user on the Samba server with the smbpasswd utility, as described in Configuring a Samba Standalone Server.

  3. Change the ownership of the credentials file.

    Set the ownership of the credentials file to the current user using the chown command. The syntax is as follows:

    sudo chown username[:groupname] credfile
  4. Change the permissions of the credentials file.

    Because the credentials file contains a plain-text password, ensure that only the owner has read access. For example, to set the appropriate permissions for the current user, run the following command:

    sudo chmod 400 credfile
  5. Mount the share.

    Mount the share using the mount command. The syntax of the mount command for mounting a Samba share using the SMBv3 protocol is as follows:

    sudo mount -t smb3 //server_name/share_name mountpoint -o credentials=credfile

    For example, the following command mounts the smb_share share from the smb_server Samba server to the local machine's /mnt/smb-share directory, using the SMB protocol and the credentials stored in the .credentials file in the user's home directory:

    sudo mount -t smb3 //smb_server/smb_share /mnt/smb-share -o credentials=~/.credentials

    You can use a specific version of the SMB protocol with the vers option. For example, to use SMB 3.0:

    sudo mount -t smb3 //smb_server/smb_share /mnt/smb-share -o credentials=~/.credentials,vers=3.0

    Note:

    If the Samba server is a domain member server in an AD domain, and the current session was authenticated by the Kerberos server in the domain, you can use the existing session credentials by specifying the sec=krb5 option instead of a credentials file. For example:

    sudo mount -t smb3 //smb_server/smb_share /mnt/smb-share -o sec=krb5

    For more information on using the mount command to mount a Samba share, see the mount.smb3(8) manual page.

  6. (Optional) Permanently mount the Samba share.

    To configure the system to mount a Samba share at boot time, add an entry for the share to the /etc/fstab file using the following syntax:

    //server_name/share_name mountpoint smb3 options

    For example, to mount the smb_share shared directory from the smb_server server to /mnt/smb-share, using the /home/user/.creds credentials file, add the following line to /etc/fstab:

    //smb_server/smb_share /mnt/smb-share smb3 credentials=/home/user/.creds