This project is no longer maintained. AWS offers two alternatives to solve similar needs:
Use your IAM user's public SSH key to get access via SSH to an EC2 instance running
aws-ec2-ssh
depends on the AWS CLI and git
if you use the install.sh
script.
A picture is worth a thousand words:
import_users.sh
)AuthorizedKeysCommand
showcase.yaml
templateCREATE_COMPLETE
PublicName
from the stack's outputsssh $Username@$PublicName
with $Username
being your IAM user, and $PublicName
with the stack's outputiam_ssh_policy.json
to the EC2 instances (by creating an IAM role and an Instance Profile)rpm -i https://s3-eu-west-1.amazonaws.com/widdix-aws-ec2-ssh-releases-eu-west-1/aws-ec2-ssh-1.9.2-1.el7.centos.noarch.rpm
/etc/aws-ec2-ssh.conf
/etc/cron.d/import_users
1Check the releases and use the latest released RPM.
iam_ssh_policy.json
to the EC2 instances (by creating an IAM role and an Instance Profile)install.sh
script as root
on the EC2 instances. Run install.sh -h
for help./etc/aws-ec2-ssh.conf
ssh $Username@$PublicName
with $Username
being your IAM user, and $PublicName
being your server's name or IP addressAllowed characters for IAM user names are:
alphanumeric, including the following common characters: plus (+), equal (=), comma (,), period (.), at (@), underscore (_), and hyphen (-).
Allowed characters for Linux user names are (POSIX ("Portable Operating System Interface for Unix") standard (IEEE Standard 1003.1 2008)):
alphanumeric, including the following common characters: period (.), underscore (_), and hyphen (-).
Therefore, characters that are allowed in IAM user names but not in Linux user names:
plus (+), equal (=), comma (,), at (@).
This solution will use the following mapping for those special characters when creating users:
+
=> .plus.
=
=> .equal.
,
=> .comma.
@
=> .at.
So instead of name@email.com
you will need to use name.at.email.com
when login via SSH.
Linux user names may only be up to 32 characters long.
There are a couple of things you can configure by editing/creating the file /etc/aws-ec2-ssh.conf
and adding
one or more of the following lines:
ASSUMEROLE="IAM-role-arn" # IAM Role ARN for multi account. See below for more info
IAM_AUTHORIZED_GROUPS="GROUPNAMES" # Comma separated list of IAM groups to import
SUDOERS_GROUPS="GROUPNAMES" # Comma seperated list of IAM groups that should have sudo access or `##ALL##` to allow all users
IAM_AUTHORIZED_GROUPS_TAG="KeyTag" # Key Tag of EC2 that contains a Comma separated list of IAM groups to import - IAM_AUTHORIZED_GROUPS_TAG will override IAM_AUTHORIZED_GROUPS, you can use only one of them
SUDOERS_GROUPS_TAG="KeyTag" # Key Tag of EC2 that contains a Comma separated list of IAM groups that should have sudo access - SUDOERS_GROUPS_TAG will override SUDOERS_GROUPS, you can use only one of them
SUDOERSGROUP="GROUPNAME" # Deprecated! IAM group that should have sudo access. Please use SUDOERS_GROUPS as this variable will be removed in future release.
LOCAL_MARKER_GROUP="iam-synced-users" # Dedicated UNIX group to mark imported users. Used for deleting removed IAM users
LOCAL_GROUPS="GROUPNAMES" # Comma seperated list of UNIX groups to add the users in
USERADD_PROGRAM="/usr/sbin/useradd" # The useradd program to use. defaults to `/usr/sbin/useradd`
USERADD_ARGS="--create-home --shell /bin/bash" # Arguments for the useradd program. defaults to `--create-home --shell /bin/bash`
USERDEL_PROGRAM="/usr/sbin/userdel" # The userdel program to use. defaults to `/usr/sbin/userdel`
USERDEL_ARGS="--force --remove" # Arguments for the userdel program. defaults to `--force --remove`
The LOCAL_MARKER_GROUP will be created if it does not exist. BEWARE: DO NOT add any manually created users to this group as they will be deleted in the next sync. This group is used by aws-ec2-ssh to keep track of what users were imported in the last run.
If you are using multiple AWS accounts you probably have one AWS account with all the IAM users (I will call it users account), and separate AWS accounts for your environments (I will call it dev account). Support for this is provided using the AssumeRole functionality in AWS.
iam_ssh_policy.json
file and replace <YOUR_USERS_ACCOUNT_ID_HERE>
with the AWS Account ID of the users account.For your EC2 instances, you need a IAM role that allows the sts:AssumeRole
action
iam_crossaccount_policy.json
file and replace <YOUR_USERS_ACCOUNT_ID_HERE>
with the AWS Account ID of the users account and <YOUR_USERS_ACCOUNT_ROLE_NAME_HERE>
with the IAM rol name that you created in the users account/etc/aws-ec2-ssh.conf
and add this line: ASSUMEROLE="IAM-ROLE-ARN
or run the install.sh script with the -a argument