I've been reading up on this a lot recently and I decided there was no real guide to help newbies to Ubuntu and newbies to rooting in the same step. I just so happened to be in that situation and attempting to root my nexus tablet. Please keep in mind this reflects my experience, with other devices and other operating systems the process is significantly different. You may / will void your warranty doing this, I am not responsible for bricked devices, etc the usual.
So first I assume since you are here that you are using Ubuntu operating system. If that does not sound familiar, take care and don't let the door hit you on the way out.
So first thing you want to do is get a fast boot environment set up. Google Linux fast boot for more information there are many different guides out there. Don't search for Ubuntu fastboot that will mostly find things related to Ubuntu touch which doesn't help us.
My process is very easy and I have tested it on both my nexus 7 and nexus 10 tablets. I know there are scripts but they are not the easiest thing for an Ubuntu first timer.
Now in your terminal (Ctrl+shift+t) you will have the world at your fingertips, but it is going to look very overwhelming at first. Don't panic, were gonna get through this. Power down your device and turn it on in boot loader mode (often power + vol up + vol down) and plug her in. I have heard the cord that came with the device must be used for this, but have not experienced any negatives with using a different one. Let's go meet fastboot. In your terminal type fastboot and check out the help menu it returns. Lots of possibilities here but we need only 2 of them.
Now, in your terminal type
Sudo fastboot devices
This will grant the terminal superuser permissions (often needed) after prompting you for your password. Then it should display a device with a long number as its name. Don't worry about this there will not be a test, but this is required to see if your fast boot command is working correctly, and whether your device is on in fastboot mode. Now we type one simple phrase to unlock the device after we verify fast boot is running.
sudo fastboot oem unlock
This will display a prompt on your device to be sure you want to unlock the device. Accept this, it will most likely wipe all of your data. (Factory reset)
Now if everything was done right you should be able to reboot your device and get it up and activated again. Unlocking your device is the only action that wipes information aside from installing custom ROMs.
Now that were unlocked we need a custom recovery. Assuming you have downloaded this already (Google is your friend) we can move on to step two. Power down your device again into fastboot mode.
In your terminal, we need to change directory to the folder housing the IMG file for your new recovery. (Default is simply Downloads which ill show you here
Type:
CD Downloads
Notice your path changes
Now let's go for it!
Sudo fastboot flash recovery (yourfilenamewithoutparentheses.IMG)
Now the worst is over. Congrats on making it this far!
Now on your device scroll through the options (volume keys) to reboot to recovery. You should see the Google logo for a moment first.
After making a backup in your recovery, go ahead and find the option to reboot (in twrp its called reboot) and reboot to system. Twrp will prompt to install supersu for you (what a nice guy) and all you need to do is open it up a couple times to update.
And thats it! Now you can run your stock rom with root access and a custom recovery. Whether you need helpful root apps like titanium backup or want a custom ROM installed you should now have all you need. I hope this helps someone!