Skip to content

Latest commit

 

History

History
168 lines (111 loc) · 5.04 KB

samba.md

File metadata and controls

168 lines (111 loc) · 5.04 KB

Samba

Description

Samba is a free software re-implementation of the SMB networking protocol, and was originally developed by Andrew Tridgell.

Directory

References


Mounting Remote Directory

Description

This details how to mount a remote directory to our local machine using Samba.

References

Steps

  1. Ensure that all necessary packages are installed, including cifs-utils, samba, and smbclient.

    [!NOTE]
    Installing samba will also install other required packages such as cifs-utils and smbclient automatically.

  2. Create the directory that will be used as the mounting point (i.e. /mnt/mynas):

    sudo mkdir /mnt/mynas
  3. Change ownership of the mounting point to our user:

    sudo chown ${USER}: /mnt/mynas
  4. Create our credentials file that will be used to access the remote directory (i.e. .smbcreds):

    mkdir -p ~/.config/smb
    nano ~/.config/smb/.smbcreds

    Content of the credentials file:

    username=mynasuser
    password=mynaspassword
    
  5. Add the IP address of our remote server to our /etc/hosts file:

    sudo nano /etc/hosts

    Sample IP address entry:

    # example.org
    192.168.0.120      mynas
  6. Add a line with our mounting options for the remote directory to our fstab file:

    • Declare the mounting options for the remote directory:

      fstab_line="//mynas/mydir   /mnt/mynas   cifs    _netdev,nofail,mfsymlinks,users,x-systemd.automount,credentials=${HOME}/.config/smb/.smbcreds,vers=3.0,uid=$(id -u),gid=$(id -g),iocharset=utf8   0 0"

      Meaning behind some of the included options:

      • //mynas/mydir: mynas denotes the sample hostname of the remote server, while mydir denotes the sample remote directory on the server.
      • /mnt/mynas: The sample directory that will be used as the mounting point.
      • _netdev: Indicates that the filesystem depends on network availability. It ensures that the mount attempt waits until the network is up.
      • nofail: Allows the boot process to continue even if this mount point fails. It prevents boot hang-ups in case the remote directory is unavailable.
      • mfsymlinks: Enables support for symbolic links in the CIFS/SMB share, allowing symbolic links on the remote system to be followed locally.
      • users: Allows non-root users to mount and unmount the filesystem.
      • x-systemd.automount: Automatically mounts the share when it is accessed, rather than at boot time. This helps avoid delays if the remote system isn't immediately available.
    • Write the line to the /etc/fstab file:

      echo "${fstab_line}" | sudo tee -a /etc/fstab
  7. Reload the daemon for it to recognise the changes made to our fstab file:

    sudo systemctl daemon-reload
  8. Mount the remote directory to our new mounting point:

    sudo mount /mnt/mynas

Unmounting a Mounted Directory

Description

This details how to mount a remote directory to our local machine using Samba.

References

Steps

  1. Unmount the remote directory from our local machine:

    sudo umount /mnt/mynas

    [!IMPORTANT]
    This example assumes that the remote directory is mounted at /mnt/mynas. Update the path accordingly.

    If you receive an error message such as the target being busy, you can use the following command to force the unmount:

    sudo umount -l /mnt/mynas

    The -l flag stands for lazy and will force the detachment of the mount point.

  2. If the previously mounted directory has been added as a mount entry in the /etc/fstab file, you can remove it by editing the file:

    sudo nano /etc/fstab

    Remove the line that corresponds to the mount point you wish to remove by deleting or commenting it out. For example:

    # example.org
    # //mynas/mydir    /mnt/mynas    cifs    _netdev,nofail,mfsymlinks,credentials=/home/deck/.config/smb/.smbcreds,vers=3.0,uid=1000,gid=1000,iocharset=utf8    0 0

    Save the file and exit the editor. This will prevent the mount point from being automatically mounted from the next boot.