Insights on Ruby, Git, jQuery, Cappuccino, WordPress, Debian and OS X. Please subscribe if you find something useful!

Avoid Sore Fingers While SSHing Around

Posted: May 14th, 2009 | Author: Jerod | Filed under: Debian | Tags: , | Comments

If you’re anything like me, you’ve gotten accustomed to commands like this:

ssh [user]@[remote.server.com]

If you find yourself connecting to the same machines repeatedly, save a few keystrokes by creating a handy alias for them. Create (or edit) “~/.ssh/config” and add as many of these as your little heart desires:

Host [the alias]
HostName [domain name or IP address]
User [the account to login as]

Now you don’t have to use the full command to access the machine, just use the alias! For example, here is how I access one of my DreamHost servers:

ssh dh

The same goes for SCP! So, to secure copy a file (my_file.txt) in my current directory to the same machine I would simply issue:

scp my_file.txt dh:

Ahh… that is easy on the fingers! What else can we do with SSH config files?


Capify – public key deployment

Posted: July 11th, 2008 | Author: Jerod | Filed under: Ruby | Tags: , | Comments

I’ve been playing with Capistrano a lot lately and loving it. Here is an example of how easy it is to write tasks and use them on multiple remote servers.

This task installs your SSH public key on the remote machine to allow key-based authentication:

set :key_file do
  Capistrano::CLI.ui.ask "enter public key to push: "
end
 
desc "configures key-based SSH administration"
task :push_key, :roles  => :all do
  key_location = File.expand_path(key_file)
  unless File.exist?(key_location) and key_file.match(/\.pub$/)
    puts "Couldn't locate public key. Try again"
    exit
  end
  key_file_name = File.basename(key_location)
  upload key_location, "/tmp/#{key_file_name}"
  run "if [ ! -e ~/.ssh ];then mkdir ~/.ssh; fi"
  run "cat /tmp/#{key_file_name} >> ~/.ssh/authorized_keys"
  run "rm /tmp/#{key_file_name}"
  run "chmod 600 ~/.ssh/authorized_keys"
end

Silky smooth.