Created
July 18, 2013 03:07
-
-
Save epylinkn/6026417 to your computer and use it in GitHub Desktop.
ssh-config => a ruby script for easily managing your ssh config shortcuts so that you don't need to type beasts like: ssh -i ~/.ssh/thisisapemkey.pem ubuntu@ec2-amazon-has-really-difficult-hostnames.amazonaws.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'thor' | |
class SSHConfig < Thor | |
desc "list", "list all hosts" | |
def list() | |
f = File.open("/Users/#{ENV['USER']}/.ssh/config", 'r') | |
hosts = f.select { |line| line =~ /Host\s/ } | |
hosts.map { |host| host[4..-1].strip }.each do |host| | |
puts host | |
end | |
end | |
desc "add [HOST] [HOSTNAME]", "add HOST shortcut for HOSTNAME to ssh config" | |
method_options :user => :string, :identity_file => :string | |
def add(host, host_name) | |
f = File.open("/Users/#{ENV['USER']}/.ssh/config", 'a') | |
f << "Host #{host}\n" | |
f << "HostName #{host_name}\n" | |
f << "User #{options[:user]}\n" if options[:user] | |
f << "IdentityFile #{options[:identity_file]}\n" if options[:identity_file] | |
f << "\n" | |
f.close | |
end | |
end | |
SSHConfig.start(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment