bash copy to clipboard

Scenario: You have written a really handy and useful bash script that does the wonders and parses the world to give you some great bit of information. This script is so useful that you constantly run it all the time. Copy’ing and Pasting the output has become your hobby.

Mac OS X: Let `pbcopy` save you. Just redirect your output to pbcopy (a built in MacOS command) and your contents go into the clipboard, ready for you to paste away. For example,

whoami | pbcopy

will copy the output of the command `whoami` into the clipboard :) Psst. There is something called `pbpaste` as well. And it does, well you guessed it. Have fun.

Linux Users: If you have X installed (I know I lost 75% of the readers right there), `xsel` does the same is a slightly ugly manner.

whoami | xsel —clipboard —input

bash autocomplete for SSH

If you are like me, and you SSH to machines through out the day, you want this. Ok. You __need__ this.

The following one liner, parses your .bash_history file and attempts to autocomplete the host you are trying to SSH to. Add this line to your .bash_profile/.bashrc file.

complete -W "$(echo $(grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //'))" ssh

Of course the lookup is limited to machines you have already SSH’d to. But whatevs, it __will__ save you time and keystrokes. Time which you could use to watch re-runs of My Little Pony.

SSH as root on EC2 Ubuntu AMIs (EDIT: works on Amazon Official AMIs as well)

Ever find yourself wanting to SSH as root into an instance launched with the official Ubuntu EC2 AMI, and you get this?

Please login as the user “ubuntu” rather than the user “root”.

If you know what you are doing and want to SSH as root, follow these steps.

  • ssh ubuntu@ (using your private key)
  • sudo -s (to become root)
  • emacs/vi /root/.ssh/authorized_keys
  • delete the lines at the begining of the file that say “COMMAND….” until you get to the words ssh-rsa
  • emacs /etc/ssh/sshd_config
  • set the variable “PermitRootLogin” to “without-password” (without quotes of course)
  • sudo /etc/init.d/sshd restart (bounce sshd)