Wednesday, February 13, 2008

Using network shares as the default Documents folders in Ubuntu

Background: in our corporate environment, we have mapped our work PCs' default locations for MyFiles, My Videos, My Pictures and My Music to a network share which is subdivided by usernames' first letter and then the username itself. The objective here is to get Ubuntu Gutsy to do the same thing just as seamlessly.

While Gutsy has a "Connect to server" functionality very similar in appearance to OS X's, its actual method of connection (GnomeVFS) is not a true mount and therefore not visible to the Linux filesystem, making it impossible to link local directories to specific subdirectories of shares. This how-to explains the basics of permanently mounting a Samba share and replacing the pertinent user directories with links to the equivalent directories on that share.

Caveat: this is aimed at desktop users. Laptop users are strongly advised to create a separate account on their laptop beforehand as outside their corporate environment they may have to VPN/PPTP authenticate before they can access network shares.

Install smbfs support


This will make your system compatible with the Samba/CIFS filesystems. If you have installed Samba file sharing for your folders, this is not the same thing and you'll still need to do the above.

Create authentication credentials

sudo nano /root/.cifsconnect and add the following lines:

Save and close out.

Create a mount point for your share

Name it after your server (why will become clear soon):
sudo mkdir /media/corporateshares

Make Ubuntu automatically mount shares after login

sudo nano /etc/fstab and add the following line at the bottom
//corpshareurl/toplevelshare /media/corporateshares cifs credentials=/root/.cifsconnect 0 0
Note it says 'cifs' and not 'smbfs'. This is because smbfs won't grant you write/delete access. Log out and back in again. You should now have a corporateshares icon on your desktop. Unlike Windows and OS X, smbfs can't mount subdirectories below the actual share, and in our case our personal directory is below that share.

Recreate Documents/Pictures/Videos/Music

Open up your Home folder and drag your Pictures, Videos, and Music folders to the Desktop so their contents don't get deleted. Right-click and remove their entries from the Nautilus sidebar.

In Terminal, do the following:


This puts symlinks in where those folders used to be. If you didn't move those folders beforehand, you'll get an error. Now, drag the new Videos/Music/Pictures/Documents folders to the Nautilus sidebar.

Now reboot your system into Linux to make sure all the settings took.

No comments: