Installing Samba on the RaspberryPi to create a file server

I'll explain how to install samba to turn your RaspberryPi into a file server.
In this article, we will only do the minimum configuration.
First connect directly to your RaspberryPi and open a terminal or connect to your RaspberryPi via SSH

## Environment
hostname: raspberrypi
username: pi

## Installing samba

Enter the following command in a terminal to install

```bash
sudo apt install samba -y
```

On the way, they ask me about my DHCP server, but I chose No this time.

## Adding a samba user

Add the samba user with the following command

```bash
sudo smbpasswd -a pi
```

You will be asked for a new password for samba users.
You will be asked to enter your password again for verification.

## Setting up smb.conf

### Backup

Backup of samba configuration files just in case

```bash
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf~
```

### Shared Directory Settings

Open smb.conf and add it to the last line with the following command

```bash
sudo nano /etc/samba/smb.conf
```

This time we will share the public directory on the home.
Configuration is minimal.
Move the cursor to the last line (Ctrl + W → Ctrl + V to jump to the last line)
Add the following

```
[share]
  path = /home/pi/Public
  writable = yes
  public = no
```

The first line [share] will be the public directory name, so please give it an easy to understand name.
path specifies the directory to be public. Please clear the writing permissions beforehand.

(If you have a usb memory stick mounted in `/mnt/usb`)

```bash:
sudo -R 777 /mnt/usb
```

### Check smb.conf

Execute the following command to display Loaded services file OK. If you can't see it, there is a mistake in smb.conf.
If it doesn't appear, there is a mistake in smb.conf, please fix it.

```bash
testparm
```

### Restart samba

Restart samba for the configuration to take effect with the following command

```bash
sudo systemctl restart smbd
```

## Connect to a shared directory

### For Windows

Type `\\raspberrypi\share` in the address bar of Explorer and in the window that appears, enter the samba user password that you set for `pi` password in the user name.
If you want to pin it as a drive, right click on your PC in the left navigation window of Explorer and select Assign Network Drive and on the screen, select the open drive and type `\\raspberrypi\share` in the folder and enter your username and password as above.

### For Linux (desktop)

Open the filer, type `smb://raspberrypi/share` in the address bar, and click Select the registered user in the screen displayed by clicking on the user name and set the pi password for samba Enter the user's password, which may be different depending on the distribution.
It may vary depending on the distribution.

### for Linux (console)
Set and mount fstab. (I won't go into it this time.

## My Accounts
<a href="https://github.com/mao2009"><img src="https://mao2009.github.io/qiita_template/GitHub-Mark-64px.png" width="50px"></a><a href="https://twitter.com/loach_mao"> <img src="https://mao2009.github.io/qiita_template/Twitter_Social_Icon_Circle_Color.png" width="50px"></a>
- - - 
Translated with www.DeepL.com/Translator (free version)