Share single .bashrc across multiple linux machines

Often I manage many servers and find myself wishing I had the same shortcuts available on my workstation, also present on the server.

Normally I’d use puppet to manage the .bashrc or .bash_profile, but my workstations don’t have a puppet master. To work around this, I store my .bash_profile on github, and have a script to update it automatically.

Here is the script to update my bash_profile

    #!/bin/bash
       curl -L https://gist.github.com/spuder/11360474/raw/ > ~/.bash_profile

https://gist.github.com/spuder/11360474

The actual bash profile is located here

    alias ls='ls -G'
    alias sl='ls -G'
    alias up='cd ..'
    alias redo='sudo \!-1'
    alias sdou='sudo'
    alias suod='sudo'
    alias sodu='sudo'
    alias tailf='tail -f'
    # Open sublime text editor with command subl
    if [ ! -f /usr/local/bin/subl ]; then /bin/ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl; fi;

https://gist.github.com/spuder/11360447

Now on every machine I manage, I run the following command just once

    curl -L https://gist.github.com/spuder/11360474/raw/ | bash -x

After that, I can just execute the bashupdate alias to pull down the latest version.

    spuder@Spuders-MacBook-Pro:~$ bashupdate

Open a new terminal, or source your ~/.bash_profile and you will instantly have the new changes. Pretty slick right?

Mount a drive in Linux

Mount a drive in Linux

I had a person ask me how to mount and unmount a drive in Ubuntu. I was unable to find a clear tutorial on how to do this, so I wrote my own.

First, understand why you would need to mount or unmount a drive. Ubuntu and most user friendly operating systems automatically mount and unmount a drive when you are in a gui. When you are operating headless or doing advanced functions you will need to know mounting.

I put a 1 GB SD card in my macbook pro for this example.

First thing is you need to find the address if the item. To do this you need to use the fdisk command. It has the same name as the program you may be familiar with in dos / windows.

Type in sudo fdisk -l

This will run fdisk as administrator. The “-l” will list all partitions.

wpid-wpid-wpid-vmwarefusion1-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

In this example there are 2 hard drives with a total of 4 partitions.

/dev/sda1
/dev/sda2
/dev/sda5

all belong to my main hard drive. The reason that it shows 3 partitions when you can only see one is that linux has a hidden system file partition and a hidden swap file. Don’t worry about this drive.

The one that we want is

/dev/sdc1

This is the 1 GB SD card. You can tell because it has 995,000 blocks and is FAT 16.

So far easy enough. Here is where people get mixed up.

When you manually mount a drive you need to give it a mount point. Think if it as a bridge between the 2 devices.
I am going to make my own mount point called “spuderMountPoint”. This mount point can be where ever you want, but common practice is to put it in the /mnt or the /media directory under root. I am goes to put my mount point in the mnt folder for this example.

Make a mount point like this.

wpid-wpid-wpid-vmwarefusion-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

Great now I have my mount point. It is time to mount the device.
-Type in “sudo mount”
-Then the address of the device. In my case it is /dev/sdc1
-Then type where you want to mount it to. In my case it is /mnt/spuderMountPoint/

wpid-wpid-wpid-1____vmwarefusion-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

It is important to note that the sdc1 is mounting partition 1 on the sd device identified by ‘c’. Don’t get this confused with windows c: drive. This example just happened to have 3 drives so it took the third letter in the alphabet.

If you wanted to mount the entire drive and not just a particular partition (this is actually recommended in most cases), just leave off the number

To mount the entire drive sda you would type

sudo mount /dev/sda /somemountpoint

To mount the third partition on a drive identified as sdf you would type

sudo mount /dev/sdf3 /somemountpoint

Mount a drive as read only

You may be doing some data recovery or working on a raid where you really don’t want to mount the drive and risk having any data written to it. In that case you will want to mount the drive as read only. This is extremely important if you are doing any kind of data forensics work or happen to get a job at the CIA and need to submit evidence that a drive hasn’t been tampered with. (Far fetched? perhaps…)

Simply add a -r to the parameters like this

sudo mount -r /dev/sda /somemountpoint

Unmount a drive

When you want to unmount a drive, simply type

sudo umount (not unmount) then the device address

wpid-wpid-wpid-2____vmwarefusion-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png