Created
December 15, 2014 20:00
-
-
Save billpatrianakos/c4b7d8c38fc441c91d79 to your computer and use it in GitHub Desktop.
Shortcut script to connect to servers via SSH without remembering IPs
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 | |
# 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]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 likeconnect pluto
. No more remembering IP addresses.