Skip to content

Instantly share code, notes, and snippets.

@0xAungkon
Last active April 7, 2026 15:01
Show Gist options
  • Select an option

  • Save 0xAungkon/48d9da955ddfebc6dadc928c01a8ef46 to your computer and use it in GitHub Desktop.

Select an option

Save 0xAungkon/48d9da955ddfebc6dadc928c01a8ef46 to your computer and use it in GitHub Desktop.
oneclick samba setup
#!/usr/bin/env bash
set -e
if ! command -v apt >/dev/null 2>&1; then
echo "Debian/Ubuntu only."
exit 1
fi
USER_NAME="${SUDO_USER:-$USER}"
sudo apt update
sudo apt install -y samba
sudo cp -n /etc/samba/smb.conf /etc/samba/smb.conf.bak
if ! grep -q "^\[homes\]" /etc/samba/smb.conf; then
sudo tee -a /etc/samba/smb.conf >/dev/null <<EOF
[homes]
comment = Home Directories
browseable = yes
writable = yes
create mask = 0700
directory mask = 0700
valid users = %S
EOF
fi
echo "Enter Samba password for user: $USER_NAME"
sudo smbpasswd -a "$USER_NAME" < /dev/tty
sudo smbpasswd -e "$USER_NAME"
sudo systemctl enable smbd nmbd
sudo systemctl restart smbd nmbd
echo "Samba configured: //$HOSTNAME/$USER_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment