ec2ssh is a ssh_config manager for Amazon EC2.
ec2ssh
command adds Host
descriptions to ssh_config (~/.ssh/config default). 'Name' tag of instances are used as Host
descriptions.
eg. Tag 'app-server-1' as 'Name' to an instance i-xxxxx in us-west-1 region.
# ~/.aws/credentials
[default]
aws_access_key_id=...
aws_secret_access_key=...
[myprofile]
aws_access_key_id=...
aws_secret_access_key=...
If you need more details about ~/.aws/credentials
, check A New and Standardized Way to Manage Credentials in the AWS SDKs
$ gem install ec2ssh
$ ec2ssh init
$ vi ~/.ec2ssh
---
profiles 'default', 'myprofile'
regions 'us-east-1'
# Ignore unnamed instances
reject {|instance| !instance.tags['Name'] }
# You can use methods of AWS::EC2::Instance.
# See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html
host_line <<END
Host <%= tags['Name'] %>.<%= availability_zone %>
HostName <%= dns_name || private_ip_address %>
END
$ ec2ssh update
Then host-names of your instances are generated and wrote to .ssh/config
$ ssh app-server-1.us-east-1a
$ ec2ssh help [TASK] # Describe available tasks or one specific task
$ ec2ssh init # Add ec2ssh mark to ssh_config
$ ec2ssh update # Update ec2 hosts list in ssh_config
$ ec2ssh remove # Remove ec2ssh mark from ssh_config
Each command can use --dotfile
option to set dotfile (.ec2ssh) path. ~/.ec2ssh
is default.
$ ec2ssh init --dotfile /path/to/ssh_config
ec2ssh init
command inserts mark lines your .ssh/config
such as:
### EC2SSH BEGIN ###
# Generated by ec2ssh http://github.com/mirakui/ec2ssh
# DO NOT edit this block!
# Updated Sun Dec 05 00:00:14 +0900 2010
### EC2SSH END ###
ec2ssh update
command inserts 'Host' descriptions between 'BEGIN' line and 'END' line.
### EC2SSH BEGIN ###
# Generated by ec2ssh http://github.com/mirakui/ec2ssh
# DO NOT edit this block!
# Updated Sun Dec 05 00:00:14 +0900 2010
# section: default
Host app-server-1.us-west-1
HostName ec2-xxx-xxx-xxx-xxx.us-west-1.compute.amazonaws.com
Host db-server-1.ap-southeast-1
HostName ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com
:
:
### EC2SSH END ###
ec2ssh remove
command removes the mark lines.
If you have used ec2ssh-1.x, it seems that you may not have '~/.ec2ssh'.
So you need execute ec2ssh init
once to create ~/.ec2ssh
, and edit it as you like.
$ ec2ssh init
$ vi ~/.ec2ssh
Dotfile (.ec2ssh
) format has been changed from YAML to Ruby DSL.
Don't panic and run ec2ssh migrate
if you have ec2ssh-2.x styled dotfile.
$ ec2ssh migrate
This command converts your existing .ec2ssh
file into 3.x style.
ec2ssh
command updates your .ssh/config
file default. You should make a backup of it.
Use zsh/_ec2ssh
.
Copyright (c) 2014 Issei Naruta. ec2ssh is released under the MIT license.