Sunday 6 November 2011

Cifs, network shares and encrypted stuff

Tidying up my network drives I'm not really in need of a full cryptonas solution but need to keep things tidy and separate.
Main files which are not important i.e photos, music etc now sit on an NTFS share as this does not inherit any linux permissions so other users can move files around without too much issue.

Files needing a backup are now on an ext3 file share (on the server main drive), called "cloud", this seems a reasonable name as this directory is replicated to the Virgin media cloud for on line backup.
The service runs through wine as its a Windows app but runs fine.
Attached to the server is also a 500gb drive, this holds copies of server config etc in case the main drive fails so I don't want people messing with this.
Originally this drive had 2 paritions 200gb and 300gb, named the same in fstab.
Since the 1tb additional drive was added I've removed the 200gb.

Access is restricted by ext3 file system and fstab entry to user id
fstab is easy enough needing just source, destination (directories), file type, auto mount (or not) and permissions.

fstab entry original mount was for 300gb partition (i've left it named as that for this post)
/dev/sdc2 /media/300gb ext3 auto,user,rw,exec 0 0 
This mounts /media/300gb locally automatically.

smb share takes care of network access anyway

smb.conf entry
[300gb]
writeable=yes
browseable=yes
valid users=kevin
user=kevin
only user =yes
path=media/300gb

This restricts user accounts on network file share.
The 300gb has chmod and chown to user:group kevin:kevin anyway so only user who owns/has access to files is me i.e kevin.


rwxr_xr_x kevin kevin
whilst chmod 755 is not really needed it's easy enough to stick with as the strict chown of kevin:kevin restricts any access to files/folders i.e I must be logged into the 300gb drive as kevin or have administrative rights above i.e root.

anyway accessing this remote through network is easy enough I either browse using network tool or can pop a command in nautilus browser bar
smb://server/300gb
this connects me up fine - the hosts file understands //server as being mapped to a fixed ip.

Next step is to get a manual fstab mount on my laptop or remote machine as I don't always need to access this drive.

Easiest way is a manual mount command specifing cifs (common Internet file system) - as I'm not mounting this as a windows share i.e linux machine to linux I don't need smb.

mount command can be mount.cifs which saves me specifying any file system parameters
I just need source and destination directories and username/password (although I can omit if needed)

manual mount test through terminal....
sudo mount.cifs //192.168.0.99/300gb /media/300gb -o username=kevin

System will prompt for "Password="
return to command prompt, check mount is there by typing mount command...
//192.168.0.99/300gb/ on /media/300gb type cifs (rw,mand)
So far so good, mount is there and I can read/write/delete files.

Next step is to pop this into a script or icon so I don't need to mount manually by typing.
unmount the drive (so I can test it later)
sudo umount /media/300gb
mount (to check it's off line)

Right click the Ubuntu Icon (top left), edit menu's.
I'm putting mine in the System tools menu.
New item



Edit the item description etc (I also changed the default icon - double click on it then pick one)
Paste the command into the command box.


In this case I've called it "mount 300gb", I suppose I should really change it to mount 500gb as I deleted the 200gb spare partition and moved the 300gb to the left then resized it to 500gb using gparted (but that's another story) but it's just a name so 300gb could just as easily be "Fred" or something.
Anyway, close the window and then go to Applications/System Tools and the new icon is there.

File runs fine, I suppose I could make an "unmount" command, in fact just done it in about 30 seconds, I've also changed the mount and unmount icons so they look similar.
The good bit is the mount will provide a double challenge, first password is for the sudo privilege, 2nd is the mount itself i.e the network share.
When unmounting you just need to provide the sudo password so the drive can't be mounted and unmounted without knowing the correct credentials.

There we go, a simple network mount via double click icon.
A nice side line, as this is now a formal mount the device /media/300gb exists as a drive, I could for example use Truecrypt and mount a network encrypted container which is held on //server/300gb.

I can do all other tasks I would want to do for example to make a full copy of my home folder to /media/300gb (network share) I could just type....


dd /home/kevin /media/300gb/backup.img

Just for fun as well I've added my own icon to the new 1tb drive, ubuntu understands the autorun and autorun.ico files so will display the icons when you mount a drive.
The new drive is a WD 1tb elements and although the icon is nice this is the new family NAS so I wanted a nas icon.

Linux is not too fussed about crappy Windows icon limits so I looked on the web, found a nice icon (resize and rename to .ico) then popped it into the autorun folder and changed the autorun file to point to it. And as they say in France "Est Voila" a nice NAS icon.
It's interesting that I tried loads of different image sizes and linux does not seem upset by large icons, where Windows has far more restrictions, I just made it a nice size purely for personal preference, not because the OS needed it. And the icon file is simply a jpg renamed.
When I've got 10 minutes I might look at changing the 300gb references to 500gb or whatever, it's just a name so not important.

Windows ... nah keep it and keep your Vauxhall Insignia SRi as well.
I've got an Avensis Diesel and it's much much much better (subtle things like the 7 inch colour, sat nav/radio screen, usb and streaming bluetooth support and so on), think of the Vauxhall as Windows and the Avensis as linux, it's much more useable and full of features.