From bd405417c078822ad235b73bcc1636bcd09a9a8f Mon Sep 17 00:00:00 2001 From: Hannes Date: Sat, 20 Jun 2026 20:11:24 +0200 Subject: [PATCH] added samba.md --- linux/samba.md | 151 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 linux/samba.md diff --git a/linux/samba.md b/linux/samba.md new file mode 100644 index 0000000..79f9ad6 --- /dev/null +++ b/linux/samba.md @@ -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 +``` + +### 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 ///Projects -o username=honney,vers=3.0 +``` + +### `/etc/fstab` entry + +```text +///Projects cifs username=honney,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 +///Projects cifs credentials=,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= +``` + +```bash +chmod 600 ~/.smbcredentials +``` + +### Find the IP of the Samba server + +```bash +ip a | grep inet +``` + +### List available shares + +```bash +smbclient -L // -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 +\\\Projects +``` + +Then log in with the samba username and password.