All articles
2 min read

Setting Up Raspberry Pi with Cockpit and File Sharing via Samba

Set up Cockpit for web-based Raspberry Pi management and Samba for network file sharing. Includes proper Samba user authentication and access from Windows, macOS, and Linux.

This guide sets up two useful tools on a Raspberry Pi running Ubuntu:

  • Cockpit — a browser-based admin panel for monitoring and managing your Pi (services, users, logs, terminal)
  • Samba — network file sharing that lets Windows, macOS, and Linux machines access folders on your Pi over the local network

Prerequisites

Update your Pi first:

sudo apt update && sudo apt upgrade -y

Part 1: Cockpit

Install

sudo apt install cockpit -y

For a newer version from backports:

. /etc/os-release
sudo apt install -t ${VERSION_CODENAME}-backports cockpit -y

Enable and Start

sudo systemctl enable --now cockpit.socket

Allow Through Firewall

sudo ufw allow 9090/tcp

Access Cockpit

Open https://<your-pi-ip>:9090 in your browser. Accept the self-signed certificate warning and log in with your Pi's system credentials.

From the dashboard you can monitor CPU/memory/disk usage, manage systemd services, view logs, and open a browser-based terminal.

Part 2: Samba File Sharing

Install Samba

sudo apt install samba cifs-utils -y

Create the Shared Directory

sudo mkdir -p /home/ubuntu/shared
sudo chown ubuntu:ubuntu /home/ubuntu/shared
sudo chmod 755 /home/ubuntu/shared

Add a Samba User

Samba uses its own password database separate from system passwords:

sudo smbpasswd -a ubuntu

Enter and confirm a password when prompted. This is the password Windows/macOS will use to connect.

Configure the Share

Edit the Samba configuration:

sudo nano /etc/samba/smb.conf

Add this section at the end of the file:

[SharedFolder]
   comment = Raspberry Pi Shared Folder
   path = /home/ubuntu/shared
   valid users = ubuntu
   read only = no
   browseable = yes
   create mask = 0644
   directory mask = 0755

This restricts access to the ubuntu user (via the Samba password you set). No anonymous access, no world-writable permissions.

Restart Samba

sudo systemctl restart smbd nmbd

Allow Through Firewall

sudo ufw allow samba

Connecting from Other Devices

Windows

Open File Explorer, click the address bar, and type:

\\<your-pi-ip>\SharedFolder

Enter the Samba username (ubuntu) and password when prompted.

macOS

In Finder, press Cmd+K and enter:

smb://<your-pi-ip>/SharedFolder

Linux

# Mount temporarily
sudo mount -t cifs //<your-pi-ip>/SharedFolder /mnt/pi \
  -o username=ubuntu,password=yourpassword

# Or open in file manager: smb://<your-pi-ip>/SharedFolder

Configuring Wi-Fi (Ubuntu Server)

If your Pi isn't connected via Ethernet, configure Wi-Fi via Netplan:

sudo nano /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      optional: true
  wifis:
    wlan0:
      dhcp4: true
      optional: true
      access-points:
        "your-wifi-ssid":
          password: "your-wifi-password"

Apply the configuration:

sudo netplan generate
sudo netplan apply

Conclusion

Cockpit gives you a practical web dashboard for day-to-day Pi management, and Samba makes your Pi a lightweight NAS that any device on your network can access. Using smbpasswd for authentication avoids the security risks of world-readable shares and guest access.