Rooting a Nexus 7

Get adb and fastboot binaries for linux.
Get the latest TWRP recovery.

Hold down Vol down and Power button for a few seconds after powering on the device, until you get the following image:

You are now in bootloader mode.

If your screen shows a red text saying: “LOCK STATE – LOCKED”, unlock it as below:

Unlocking a Nexus 7:

Run fastboot in bootloader mode:

sudo fastboot oem unlock

Confirm by pressing the power button

When it says “Unlocked”, you can proceed

Rooting a unlocked Nexus 7:
You need to install a custom recovery.
In bootloader mode, run:

sudo fastboot flash recovery downloads/openrecovery-twrp-2.6.3.1-grouper.img

Now choose Recovery by selecting using the Vol up/down keys.
Once TWRP loads, select to reboot to recovery. TWRP will prompt you to root your device. Elect to do that.
Note: Everything on your device will be wiped at this point, and system boots as if for the first time.

Once device boots, enter the details asked for, and click Super SU installer in the menu. Update SU from Play store, and elect to root. On restarting your device, it will be rooted.