docs(samba): add install, configure, and uninstall recipes
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
# Install Samba
|
||||
|
||||
This recipe installs Samba on Ubuntu, enables the required services, and configures a basic file share.
|
||||
|
||||
## Install Packages
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install -y samba
|
||||
```
|
||||
|
||||
## Verify Installation
|
||||
|
||||
```bash
|
||||
smbd --version
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
Version 4.x.x
|
||||
```
|
||||
|
||||
## Enable Services
|
||||
|
||||
```bash
|
||||
sudo systemctl enable smbd
|
||||
sudo systemctl enable nmbd
|
||||
sudo systemctl start smbd
|
||||
sudo systemctl start nmbd
|
||||
```
|
||||
|
||||
## Verify Services
|
||||
|
||||
```bash
|
||||
systemctl status smbd --no-pager
|
||||
systemctl status nmbd --no-pager
|
||||
```
|
||||
|
||||
Both services should be reported as **active (running)**.
|
||||
|
||||
## Configure Samba
|
||||
|
||||
Replace the default configuration.
|
||||
|
||||
```bash
|
||||
sudo cp smb.conf /etc/samba/smb.conf
|
||||
```
|
||||
|
||||
Validate the configuration.
|
||||
|
||||
```bash
|
||||
testparm
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
Loaded services file OK.
|
||||
```
|
||||
|
||||
## Restart Samba
|
||||
|
||||
```bash
|
||||
sudo systemctl restart smbd
|
||||
sudo systemctl restart nmbd
|
||||
```
|
||||
|
||||
## Configure Firewall (Optional)
|
||||
|
||||
If UFW is enabled:
|
||||
|
||||
```bash
|
||||
sudo ufw allow samba
|
||||
```
|
||||
|
||||
## Verify Listening Ports
|
||||
|
||||
```bash
|
||||
sudo ss -tulpn | grep smb
|
||||
```
|
||||
|
||||
Expected output should include ports **139** and **445**.
|
||||
|
||||
## Create Samba User (Optional)
|
||||
|
||||
```bash
|
||||
sudo smbpasswd -a <username>
|
||||
sudo smbpasswd -e <username>
|
||||
```
|
||||
|
||||
List configured Samba users.
|
||||
|
||||
```bash
|
||||
sudo pdbedit -L
|
||||
```
|
||||
@@ -0,0 +1,89 @@
|
||||
# Configure Samba Share
|
||||
|
||||
This recipe configures a basic Samba file share.
|
||||
|
||||
## Backup Existing Configuration
|
||||
|
||||
```bash
|
||||
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
|
||||
```
|
||||
|
||||
## Create Configuration
|
||||
|
||||
Replace the existing configuration.
|
||||
|
||||
```bash
|
||||
sudo tee /etc/samba/smb.conf >/dev/null <<'EOF'
|
||||
[global]
|
||||
workgroup = WORKGROUP
|
||||
server string = Samba Server
|
||||
security = user
|
||||
map to guest = Bad User
|
||||
|
||||
[Share]
|
||||
path = /srv/samba
|
||||
browseable = yes
|
||||
writable = yes
|
||||
guest ok = no
|
||||
read only = no
|
||||
create mask = 0664
|
||||
directory mask = 0775
|
||||
EOF
|
||||
```
|
||||
|
||||
## Create Share Directory
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /srv/samba
|
||||
```
|
||||
|
||||
## Configure Permissions
|
||||
|
||||
Replace `<username>` with your Linux username.
|
||||
|
||||
```bash
|
||||
sudo chown -R <username>:<username> /srv/samba
|
||||
sudo chmod -R 775 /srv/samba
|
||||
```
|
||||
|
||||
## Create Samba User
|
||||
|
||||
If the user does not already exist on Linux, create it first.
|
||||
|
||||
```bash
|
||||
sudo smbpasswd -a <username>
|
||||
sudo smbpasswd -e <username>
|
||||
```
|
||||
|
||||
## Validate Configuration
|
||||
|
||||
```bash
|
||||
testparm
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
Loaded services file OK.
|
||||
```
|
||||
|
||||
## Restart Samba
|
||||
|
||||
```bash
|
||||
sudo systemctl restart smbd
|
||||
sudo systemctl restart nmbd
|
||||
```
|
||||
|
||||
## Verify Share
|
||||
|
||||
```bash
|
||||
smbclient -L localhost -U <username>
|
||||
```
|
||||
|
||||
Expected output should include:
|
||||
|
||||
```text
|
||||
Sharename Type
|
||||
--------- ----
|
||||
Share Disk
|
||||
```
|
||||
@@ -0,0 +1,83 @@
|
||||
# Uninstall Samba
|
||||
|
||||
This recipe completely removes Samba from Ubuntu, including services, packages, and configuration files.
|
||||
|
||||
## Stop Services
|
||||
|
||||
```bash
|
||||
sudo systemctl stop smbd
|
||||
sudo systemctl stop nmbd
|
||||
```
|
||||
|
||||
## Disable Services
|
||||
|
||||
```bash
|
||||
sudo systemctl disable smbd
|
||||
sudo systemctl disable nmbd
|
||||
```
|
||||
|
||||
## Remove Packages
|
||||
|
||||
```bash
|
||||
sudo apt purge -y samba samba-common samba-common-bin smbclient
|
||||
sudo apt autoremove -y
|
||||
```
|
||||
|
||||
## Remove Configuration
|
||||
|
||||
```bash
|
||||
sudo rm -rf /etc/samba
|
||||
sudo rm -rf /var/lib/samba
|
||||
sudo rm -rf /var/cache/samba
|
||||
sudo rm -rf /var/log/samba
|
||||
```
|
||||
|
||||
## Remove Firewall Rule (Optional)
|
||||
|
||||
If UFW was configured:
|
||||
|
||||
```bash
|
||||
sudo ufw delete allow samba
|
||||
```
|
||||
|
||||
## Remove Shared Directories (Optional)
|
||||
|
||||
Only run this if the directory was created exclusively for Samba and does not contain important files.
|
||||
|
||||
```bash
|
||||
sudo rm -rf /srv/samba
|
||||
```
|
||||
|
||||
## Verify Removal
|
||||
|
||||
Check that the package is no longer installed.
|
||||
|
||||
```bash
|
||||
dpkg -l | grep samba
|
||||
```
|
||||
|
||||
No packages should be listed.
|
||||
|
||||
Verify that the service no longer exists.
|
||||
|
||||
```bash
|
||||
systemctl status smbd
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
Unit smbd.service could not be found.
|
||||
```
|
||||
|
||||
Verify that the configuration directory has been removed.
|
||||
|
||||
```bash
|
||||
ls /etc/samba
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
ls: cannot access '/etc/samba': No such file or directory
|
||||
```
|
||||
Reference in New Issue
Block a user