Ubuntu Samba Install

Following on from my efforts building a dedicated data recovery box, I decided to use Samba as an easy way of looking through the recovered data, in addition to the local client disks.

First of all, a quick update as always to check the latest packages in the repo:

root@moe:~# apt update && apt upgrade -y

Next the samba install:

root@moe:~# apt install samba -y

The samba setup required is very simple, I want one account with write access, then a guest account with read access for everyone else. Make sure you understand the implications of this insecure configuration before blindly following it. My folder structure is very basic, with everything from the /media directory being visible.

Rather than wade through the sea of options in the default config file, I simply backed it up and started from a blank slate.

root@moe:~# mv /etc/samba/smb.conf /etc/samba/smb.conf.original
root@moe:~# vi /etc/samba/smb.conf

I then used the following config in the new smb.conf file

======================= Global Settings =======================
[global]
workgroup = WORKGROUP
dns proxy = no
load printers = no
printcap name = /dev/null
disable spoolss = yes

#### Networking ####
interfaces = 127.0.0.0/8
bind interfaces only = yes

#### Debugging/Accounting ####
log file = /var/log/samba/log.%m
max log size = 1000

####### Authentication #######
server role = standalone server
passdb backend = tdbsam
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user

############ Misc ############
usershare allow guests = yes

#======================= Share Definitions =======================
[media]
comment = Media Share on Moe
path = /media
valid users = "jon"
write list = "jon"
guest ok = no
browseable = no


[store]
comment = Data Store on Moe
path = /media/store/
read only = yes
guest ok = yes

Once you have saved the file, use the testparm command to check for configuration errors. Then simply restart as below:

root@moe:~# service smbd restart
root@moe:~# service smbd status
● smbd.service - Samba SMB Daemon
   Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-05-07 11:04:22 UTC; 4s ago
     Docs: man:smbd(8)
           man:samba(7)
           man:smb.conf(5)
 Main PID: 28444 (smbd)
   Status: "smbd: ready to serve connections..."
    Tasks: 3 (limit: 4915)
   CGroup: /system.slice/smbd.service
           ├─28444 /usr/sbin/smbd --foreground --no-process-group
           ├─28479 /usr/sbin/smbd --foreground --no-process-group
           └─28480 /usr/sbin/smbd --foreground --no-process-group


May 07 11:04:22 moe systemd[1]: Starting Samba SMB Daemon...
May 07 11:04:22 moe systemd[1]: Started Samba SMB Daemon.
May 07 11:04:22 moe smbd[28444]: [2020/05/07 11:04:22.166574,  0] ../lib/util/become_daemon.c:124(daemon_ready)
May 07 11:04:22 moe smbd[28444]:   STATUS=daemon 'smbd' finished starting up and ready to serve connections
root@moe:~# 
root@moe:~# 

I can’t stress enough that this is far from a secure or recommended setup. However in my single use case it is fine, I’m only working on data believed to be lost, and this isn’t my livelyhood.

Disk Recovery Ubuntu Box

The Background

After years of having multiple floppies, SCSI, IDE, SATA, USB drives and sticks kicking around the office I’ve decided it can’t carry on like this. I’ve fallen into the habit of buying the biggest USB disk I could afford to shuffle data back and forth between new and old machines as I nuke and pave my way through life.

I’ve also had numerous requests from family and friends over the years to rebuild machines or recover data for them which has just added to my problem. I always like to have two copies of the data when doing anything like this for security against mistakes (of which there have been a few).

The end result is more disks and sticks kicking around with no order or structure. Every time I’ve started to have a sort out in the past, I’ve always ran out of space or needed the device I was loading disks in for real work.

Whilst having a sort out I have come across an old HP xw4600 workstation which has a ton of space inside, 4 SATA ports and even IDE It isn’t the most powerful on the processor front, but it will be perfect for a box I can use as a dedicated platform for this task.

So after digging through the old disks and finding an empty 120G SSD from some unknown source, I connected it up to SATA0 and started installing Ubuntu Server. Even though I’m planning on doing most of the work on the command line via SSH, I decided to install LightDM and LXDE just incase I needed some GUI tools later.

20 minutes later, I have a box which I can wake up remotely from a so called magic packet. In less than 25 seconds later, I can log in locally through the GUI or remotely via SSH, ideal. Now for some more interesting bits. Obviously as with all devices these days some precautions on the security front should be taken to protect against the evils on the Internet.

The Customisation Journey

I say Journey, as I never seem to get to a fully configured server, but once the basic ubuntu server build is there, I’ll add some tools etc I require. First off I’ll add the usb auto mount functionality as used in the ubuntu desktop variants along with support for NTFS as I know there will be some old MS Windows disks to go through. Finally here I’ll get the testdisk utilities installed which also provides PhotoRec.

jon@moe:~$ sudo apt update && sudo apt install usbmount ntfs-3g testdisk

Now when I plug a USB Device (disk or stick) it gets auto mounted under /dev/usb? somewhere. This just safes me the bother of doing it manually.

I decided to add a GUI as some of the tools I may use in the future may require it. I went for a simple default lxde core.

jon@moe:~$ sudo apt update && sudo apt install lightdm tasksel -y
<snip>
jon@moe:~$ sudo tasksel install Lubuntu-core
<snip>

Data Recovery Example

A grand total of 45 minutes since starting I’ve got a platform built, now with two extra drives connected. A blank data disk, and a drive which was inadvertently formatted that I need to recover data from. Some 3 hours later, and PhotoRec has already recovered 800+ jpg files.

PhotoRec 7.0, Data Recovery Utility, April 2015
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org

Disk /dev/sdb - 4000 GB / 3726 GiB (RO) - WDC WD40PURZ-85TUZV0
     Partition                  Start        End    Size in sectors
     No partition             0   0  1 486401  80 63 7814037168 [Whole disk]

Pass 1 - Reading sector  439340400/7814037168, 843 files found
Elapsed time 3h47m26s - Estimated time to completion 63h37m39
jpg: 843 recovered

It is now well past half way, according to the disk geometry, but I will let it run through to its conclusion. Just for the record, it didn’t take the estimated 63 hours, it completed overnight.