added samba.md
This commit is contained in:
+151
@@ -0,0 +1,151 @@
|
|||||||
|
# Samba Share
|
||||||
|
|
||||||
|
A Samba share lets you access files on this machine over the network (Windows SMB protocol).
|
||||||
|
|
||||||
|
`<>` - Is used to mark that you need to fill that in
|
||||||
|
|
||||||
|
## Initial Setup (one-time)
|
||||||
|
|
||||||
|
### 1. Install Samba
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo pacman -S samba # Arch
|
||||||
|
sudo apt install samba # Debian/Ubuntu
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Create a Samba user
|
||||||
|
|
||||||
|
The samba password is **separate** from your system password.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo smbpasswd -a <username>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Edit `/etc/samba/smb.conf`
|
||||||
|
|
||||||
|
Example config for sharing the Projects folder:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[global]
|
||||||
|
workgroup = WORKGROUP
|
||||||
|
server string = %h
|
||||||
|
map to guest = Bad User
|
||||||
|
log file = /var/log/samba/%m.log
|
||||||
|
max log size = 50
|
||||||
|
socket options = TCP_NODELAY
|
||||||
|
|
||||||
|
[Projects]
|
||||||
|
comment = Projects
|
||||||
|
path = /home/honney/Projects
|
||||||
|
browseable = yes
|
||||||
|
read only = no
|
||||||
|
writable = yes
|
||||||
|
valid users = honney
|
||||||
|
create mask = 0664
|
||||||
|
directory mask = 0775
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Start Samba
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable --now smb
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Allow Samba through the firewall
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo firewall-cmd --add-service=samba --permanent
|
||||||
|
sudo firewall-cmd --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
Or with `ufw`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ufw allow samba
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mounting the share on another Linux machine
|
||||||
|
|
||||||
|
Install `cifs-utils`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo pacman -S cifs-utils # Arch
|
||||||
|
sudo apt install cifs-utils # Debian/Ubuntu
|
||||||
|
```
|
||||||
|
|
||||||
|
Mount manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mount -t cifs //<IP>/Projects </path/to/mount> -o username=honney,vers=3.0
|
||||||
|
```
|
||||||
|
|
||||||
|
### `/etc/fstab` entry
|
||||||
|
|
||||||
|
```text
|
||||||
|
//<IP>/Projects </path/to/mount> cifs username=honney,password=<password>,vers=3.0,nofail,uid=1000,gid=1000,iocharset=utf8,file_mode=0664,dir_mode=0775 0 0
|
||||||
|
```
|
||||||
|
|
||||||
|
Or with a credentials file (more secure):
|
||||||
|
|
||||||
|
```text
|
||||||
|
//<IP>/Projects </path/to/mount> cifs credentials=</path/to/.smbcredentials>,vers=3.0,nofail,uid=1000,gid=1000,iocharset=utf8,file_mode=0664,dir_mode=0775 0 0
|
||||||
|
```
|
||||||
|
|
||||||
|
Credentials file (`~/.smbcredentials`):
|
||||||
|
|
||||||
|
```text
|
||||||
|
username=honney
|
||||||
|
password=<password>
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod 600 ~/.smbcredentials
|
||||||
|
```
|
||||||
|
|
||||||
|
### Find the IP of the Samba server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip a | grep inet
|
||||||
|
```
|
||||||
|
|
||||||
|
### List available shares
|
||||||
|
|
||||||
|
```bash
|
||||||
|
smbclient -L //<IP> -U honney
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
Check if Samba is running:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl status smb
|
||||||
|
```
|
||||||
|
|
||||||
|
View active connections:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo smbstatus
|
||||||
|
```
|
||||||
|
|
||||||
|
Test the config for errors:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
testparm
|
||||||
|
```
|
||||||
|
|
||||||
|
Restart Samba after config changes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl restart smb
|
||||||
|
```
|
||||||
|
|
||||||
|
## Access from Windows
|
||||||
|
|
||||||
|
Open File Explorer and type:
|
||||||
|
|
||||||
|
```text
|
||||||
|
\\<IP>\Projects
|
||||||
|
```
|
||||||
|
|
||||||
|
Then log in with the samba username and password.
|
||||||
Reference in New Issue
Block a user