Install, Configure And Run Samba To Make USB Hard Drive Shared Across Network

Last Edited: 2015-04-18 17:12:27


Once upon a time in a cubicle not all that far away, I needed to connect my work computer running Windows 7 to a linux box to move some files around. The files were for a unbelievably terrible product known as Magento. I have no problem saying that Magento is garbage now that I've worked with it for the past two years; I can prove it with evidence. But that is another story (that I will be blogging about when Magento 2 comes out). Anyhow, Magento is a 30,000 file monster. It also comes with a 500+ table database. We're working at an IBM shop so we wanted to see if that was the reason Magento sucked (it's wasn't IBM) so we moved it to a linux server that's on an available IP address. I was super excited to find samba and that it was already installed and ready to go!!


For those of you who don't know, samba is a server that can run on linux that can allow you to connect to the server and access drives and other peripherals upon said linux computer. With a quick and simple configuration, I was up and running.


So then later, at home, I ran into this issue with my external hard drive. I have a 1TB hard drive that I've been shucking information onto for the past 5 years or so. It's great! But it's USB so I've always just plugged it into my laptop when I needed it. I enjoy the fact that my laptop is portable (duh) so I don't necessarily like being tethered to a desk. I also don't like the fact that 67% of the time I need a file on that TB hard drive, it's in the other room. Oh, bullocks. (Sidenote: I know this is a ridiculous 1st world problem; I am thankful for having another room to need to walk to)


As you may not know, my linux box is a headless server so there's not GUI, no keyboard and no monitor. Setting up the USB drive as a share for the internal network needed to be done strictly by command line. So here we go...


Started by plugging in the USB hard drive to an available USB port on the computer. Then I need a place to put it in the file system. I've named the disk "Terabyte" because when I got it a terabyte was a LOT of room! Not so much now, still a cool name. I decided to make the mounting point the same so...


freddythunder@crunchbang:~$ cd /mnt
freddythunder@crunchbang:/mnt$ sudo mkdir Terabyte

Then I found out what my USB drive /dev/ connection name by doing this:


freddythunder@crunchbang:/mnt$ sudo lshw
...
*-disk
description: SCSI Disk
product: My Book 1110
vendor: WD
physical id: 0.0.0
bus info: scsi@6:0.0.0
logical name: /dev/sdh
version: 2003
serial: WCAV57831023
size: 930GiB (999GB)
capabilities: gpt-1.00 partitioned partitioned:gpt
configuration: ansiversion=4 guid=c685b15c-0788-4d9b-a2db-933281a0eec6 sectorsize=512
*-volume:0
description: Windows FAT volume
vendor: BSD 4.4
physical id: 1
bus info: scsi@6:0.0.0,1
logical name: /dev/sdh1
version: FAT32
serial: 70d6-1701
size: 199MiB
capacity: 199MiB
capabilities: boot fat initialized
configuration: FATs=2 filesystem=fat label=EFI name=EFI System Partition
*-volume:1
description: Apple HFS+ partition
vendor: Mac OS X (journaled)
physical id: 2
bus info: scsi@6:0.0.0,2
logical name: /dev/sdh2
logical name: /mnt/Terabyte
version: 5
serial: 9a269f8d-a4ae-f737-0000-000001d15000
size: 930GiB
capabilities: hfsx journaled hfsplus initialized
...

Whoa! That's a lot a crap!! Is what I thought when I first did this. It's good to note that you can also do sudo lswh -class disk to just show disks on the machine, but that did not show me the different volumes on this particular disk. As you can see what I put in bold above, the logical name for the larger sized volume is /dev/sdh2. This is the piece of info you need to connect the directory you made to the USB drive. Another way to check out what drives and volumes you put in is doing dmesg | tail right after plugging in your USB drive - you can do this with thumb drives too! It will list both sdh1 and sdh2, then you can mount them and see which one you need (or can mount to). Then the command to mount the disk that I use is:


freddythunder@crunchbang:/mnt$ sudo mount -o umask=0 /dev/sdh2 /mnt/Terabyte

If you don't get any errors, then you've mounted your disk. You can then cd to /mnt/Terabyte and do an ls to see its contents. Hooray!


Configuring and Running Samba


I ran into a couple issues with my version of linux (Debian, Crunchbang). I was able to find /etc/samba/smb.conf, and I was able to configure it, but I wasn't able to connect from my mac! Since I'm only going to report what worked I will bore you with other details at a later date... The configuration changes I made were like this:



[Terabyte]
comment = External USB Drive
path = /mnt/Terabyte
available = yes
valid users = freddythunder
read only = no
browseable = yes
public = no
writable = yes
guest ok = yes
create mask = 0755

I added that right to then end of /etc/samba/smb.conf AFTER doing


freddythunder@crunchbang:/mnt$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bu

That way I can always start again after I screw things up. I still could not connect. When I did these configuration changes at work, I don't remember if I had to restart samba or not, but tried to restart samba. I tried what I thought would work:



freddythunder@crunchbang:/etc/samba$ sudo service smb restart
smb: unrecognized service
freddythunder@crunchbang:/etc/samba$ sudo service samba restart
samba: unrecognized service
freddythunder@crunchbang:/etc/samba$ sudo service smb restart
smb: unrecognized service

But that did not work. I looked in the /etc/init.d directory for anything samba-related... nothing. So that's weird. I wonder if anyone else had this problem before? I have a configuration file to a piece of software I don't have. Cool beans. I tried looking in the running processes ps -A | grep 'samba' and nothing, and tried listing all processes service --status-all nothing. Then I got crazy and tried to install samba!!


freddythunder@crunchbang:/mnt$ sudo apt-get install samba

If samba didn't need anything, the package manager apt-get would let me know, but it needed to install, I said "Y" to let it continue and it went through the installation process. I got a screen notifying me that the config file had changed (changes above) and if I wanted to keep them or use the package manager's version. I chose the package manager's version. I figured I could just put my changes back. After it was finished, it started the daemons smbd and nmbd. There were just a few more changes I needed to make permissions-wise that I read in a different website.


The other tutorial I found did not do things the way that worked, so I won't link to them. I will say that I ran these commands to add a user to samba, add a password, change the ownership of the USB drive link to the samba group and then add my user to the group. At the end of the samba installation, it told me that it created a group called sambashare so I will use the group the package manager created. I will comment below:


//add the samba user
freddythunder@crunchbang:/mnt$ sudo smbpasswd -a freddythunder
//this prompted for a password and to verify the password
//then change the ownership of the USB drive link
freddythunder@crunchbang:/mnt$ sudo chown :sambashare /mnt/Terabyte
//add the new user I created with smbpasswd to the group
freddythunder@crunchbang:/mnt$ sudo usermod -G sambashare freddythunder

Glad that's done. Here's a tip... If you want to see if that sambashare group is in your groups, do a more /etc/group and you'll see a list of all your groups. In my case, sambashare was the last one.


Connect to Your Samba Share with Your Mac


I have a 10.10.2 OS X Yosemite that I recently got. I ran into some incorrect information on the interwebs on how to connect it, but was able to do it this way the most simply... I did not use command line. Open Finder. Then at the top of the screen, click Go > Connect to Server - or a squiggly key K. Then put in: the IP address of the server you want to connect to. At that point, I was able to put in the new username and password I had created and select Terabyte icon and I got my drive as a shared drive on my finder. Finders keepers.



Comments

Categories

Recent Posts