johnsonmlw.github.io/johnsonmlw

Table of Contents

1. Context

  • The following notes are for Debian Bookworm but should be reasonably transferrable to other linux/unix setups
  • This page is written with org-mode on Emacs

2. Hints for these notes

  • Ctrl (the keyboard control key) is represented in these notes a C; Alt key is M (for meta)
  • Copy or paste in a PuTTY session with C-right click
  • Linux commands below assume the user is logged in as root (could prepend sudo to each command instead)
  • Emacs is the chosen editor below; a simple alternative is nano which has the advantage of likely being installed already

3. Editor

3.1. Emacs

Basic emacs commands

  • C-x C-f Find file (open)
  • C-x C-s Save
  • C-x C-c Quit
  • C-o Open recent file (once configured as below)
  • C-k Cut this line (kill)
  • C-y Paste (yank)

Install and configure

  • Install
    # apt install emacs
    
  • Confgure basic useful setup (here we create our .emacs config file)
    # emacs .emacs
    
  • Paste the following
    (require 'package)
    (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
    (package-initialize)
    
    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     '(global-visual-line-mode t)
     '(inhibit-startup-screen t)
     '(ring-bell-function 'ignore)
     '(scroll-bar-mode nil)
     '(tool-bar-mode nil)
     '(window-divider-mode nil))
    
    (recentf-mode 1)
    (global-set-key "\C-o" 'recentf-open-files)
    (menu-bar-mode -1)
    (fido-vertical-mode 1)
    
    (setq make-backup-files nil)
    (setq recentf-max-menu-items 25)
    (setq warning-minimum-level :error)
    

4. Samba

4.1. Preparation

Install and configure

  • Install Samba
    # apt install samba
    
  • Optionally, rename the Debian default Samba configuration file to begin with a blank
    # mv /etc/samba/smb.{conf,conf.orig}
    

4.2. A simple share, read/write for anyone

  • Ownership of all new directories and files created by any samba client (e.g. Windows) is simplified by force user = sam (where sam is any standard linux user account)

Linux directories

  • Create share directory and change its ownership to a standard linux user account (where sam is any standard linux user account)
    # mkdir /srv/share
    # chown sam:sam /srv/share
    

Configure samba

  • Edit /etc/samba/smb.conf
    # emacs /etc/samba/smb.conf
    
    [global]
    map to guest = Bad User
    
    [share]
    path = /srv/share
    guest ok = yes
    writeable = yes
    force user = sam
    
  • Reload samba
    # systemctl reload smb
    

Anonymous access

  • For the simplest of guest shares, we can avoid clients (e.g. Windows) even asking our guest for a username and password by having exactly zero samba user accounts
  • If these have been previously created and are not needed, optionally delete all samba accounts
  • List smb users
    # pdbedit -L -v
    
  • Delete each smb user
    # pdbedit -x -u sam
    

4.3. Private user shares, and shared read/write for anyone

  • Two users (sam and ba) each need a private directory; there is also a writeable shared directory
  • We assume that users sam and ba have linux user accounts (not covered here)
  • directory mask and create mask ensure that new directories and files users create in [share] can be written to and deleted by any user

Linux directories

  • Create user sam's directory, change ownership and linux permission
    # mkdir /srv/sam
    # chown sam:sam /srv/sam
    # chmod 0700 /srv/sam
    
  • Create user ba's directory, change ownership and linux permission
    # mkdir /srv/ba
    # chown ba:ba /srv/ba
    # chmod 0700 /srv/ba
    

Configure samba

  • Edit /etc/samba/smb.conf
    # emacs /etc/samba/smb.conf
    
    [global]
    map to guest = Bad User
    
    [sam]
    path = /srv/sam
    valid users = sam
    writeable = yes
    
    [ba]
    path = /srv/ba
    valid users = ba
    writeable = yes
    
    [share]
    path = /srv/share
    valid users = sam, ba
    writeable = yes
    directory mask = 0777
    create mask = 0666
    
  • Reload samba
    # systemctl reload smb
    

Users sam and ba need samba user accounts (in addition to their linux accounts)

# pdbedit -a -u sam
# pdbedit -a -u ba

Author: M Johnson

Created: 2024-03-14 Thu 17:52

Validate