# Accessing a share (rclone + SMB)

### Introduction

This guide teaches you how to access a network share using **rclone** via the **SMB** protocol.

<p class="callout warning">This guide assumed that you have established a connection to my network; see [Connecting to my network](https://wiki.joris.me/books/network-storage/chapter/connecting-to-my-network) if you haven't already.</p>

### Before we begin..

<p class="callout danger">I SHALL NOT BE LIABLE FOR ANY DAMAGES OR LOSSES ARISING FROM ANY USE OF THE NETWORK SHARE, INCLUDING ANY INTERRUPTIONS TO THE NETWORK SHARE, INCLUDING, BUT NOT LIMITED TO, ANY POWER OUTAGES, SYSTEM FAILURES, NETWORK ATTACKS, SCHEDULED OR UNSCHEDULED MAINTENANCE, OR OTHER INTERRUPTIONS.</p>

<p class="callout danger">**YOU** are responsible for keeping enough backups of your data**.**</p>

<p class="callout info">**Recommended** reading: [https://www.backblaze.com/blog/the-3-2-1-backup-strategy/](https://www.backblaze.com/blog/the-3-2-1-backup-strategy/)</p>

With that out of the way, let's begin!

### Prerequisites

- A Linux machine;
- A working [WireGuard](https://wiki.joris.me/books/network-storage/page/connecting-via-wireguard) or [Tailscale](https://wiki.joris.me/books/network-storage/page/connecting-via-tailscale) connection to my homelab;
- The following three strings: 
    - The **share name**;
    - The **username** for SMB authentication;
    - The **password** for SMB authentication.

### Installing dependencies

We only really need to install `rclone`.

#### On Debian

```bash
sudo apt install rclone
```

#### On Arch Linux

```bash
sudo pacman -S rclone
```

### Adding the remote

```bash
$> rclone config
Current remotes:

Name                 Type
====                 ====
unrelated1           http
unrelated2           smb

# ..bla bla..
e/n/d/r/c/s/q> n

# Choose a name for your remote:
name> example_smb

# A very long list appears, you can ignore it.
# Just write:
Storage> smb

# Enter this host exactly:
Option host.
host> truenas.storage.jorislab.nl

# Enter your first name, in lower case. For example:
Option user.
user> joris

# Port number: default
port> # press Enter

# Use a password? Yes.
Option pass.
y/g/n> y

Enter the password:
password: # Paste the password you were given.
Confirm the password:
password: # Paste it again.

# No specific domain
domain> # press Enter

Edit advanced config?
y/n> n # No

# Save the remote.
Keep this "example" remote?
y/e/d> y # yes

# You should now land back at the start.
# Write 'q' to exit
e/n/d/r/c/s/q> q
```

### Testing the remote

After exiting the interactive CLI, you should now be able to run:

```bash
# Format: <remote>:<path>
$> rclone ls example_smb:/example/
```

<p class="callout info">It might seem odd to write 'example' as path here. The format is `<remote>:<path>`. However, SMB is a directory, even at the very top level: the root directory is just a list of shares. Because of this you first have to write your share name as the first 'folder' in the path. Folders and files below that are yours.</p>

To test reading and writing:

```bash
# Create a file:
$> echo hello > hello.txt

# Copy the file to the remote:
$> rclone copy hello.txt example_smb:/example/

# List files in the remote:
$> rclone ls example_smb:/example/
        6 hello.txt

```

### Wrapping up

I suggest heading over to the [rclone docs](https://rclone.org/) to find how you want to utilize rclone effectively. The two most common use-cases I've found are `rclone copy` and `rclone sync`; the only difference being that the latter also deletes files.

<p class="callout success">And we're done! Enjoy!</p>