Skip to content

Instantly share code, notes, and snippets.

@billpatrianakos
Created December 15, 2014 20:00
Show Gist options
  • Save billpatrianakos/c4b7d8c38fc441c91d79 to your computer and use it in GitHub Desktop.
Save billpatrianakos/c4b7d8c38fc441c91d79 to your computer and use it in GitHub Desktop.
Shortcut script to connect to servers via SSH without remembering IPs
#!/usr/bin/env ruby
# Connect
#
# Connects to a server by name and user
# Usage: Run `connect <hostname> <user>`
# <user> is optional and defaults to '<REPLACE WITH YOUR OWN DEFAULT>'
if ARGV[0].nil?
puts <<-END
Please specify a hostname. USAGE:
connect <host> <username> - Username is optional
END
exit 1
end
host = ARGV[0].to_sym
user = ARGV[1].nil? ? 'user' : ARGV[1] # REPLACE 'user' with your preferred default username
hosts = {
pluto: '123.45.6.78',
minnie: '345.667.8.9'
# Add as many hosts as you'd like here
}
puts "Connecting #{user} to #{hosts[host]}..."
system("ssh #{user}@#{hosts[host]}")
@billpatrianakos
Copy link
Author

Edit the default user variable and change the hosts hash to match your servers. Place somewhere on your system, make it executable with chmod +x scriptname and run it whenever you need to connect to one of your servers like connect pluto. No more remembering IP addresses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment