Giter Site home page Giter Site logo

aws-ec2-ssh's Introduction

Manage AWS EC2 SSH access with IAM

This showcase demonstrates how you can use your IAM user's public SSH key to get access via SSH to an EC2 instance.

How does it work

A picture is worth a thousand words:

Architecture

  • On first start all IAM users are imported and local users are created
  • The import also runs every 10 minutes (via cron - calls import_users.sh)
  • On every SSH login the EC2 instance tries to fetch the public key(s) from IAM using sshd's AuthorizedKeysCommand
  • You can restrict that the EC2 instance is only allowed to download public keys from certain IAM users instead of *. This way you can restrict SSH access within your account
  • As soon as the public SSH key is deleted from the IAM user a login is no longer possible

How to run this showcase (CloudFormation)

  1. Upload your public SSH key to IAM:
  2. Open the Users section in the IAM Management Console
  3. Click the row with your user
  4. Click the "Upload SSH public key" button at the bottom of the page
  5. Paste your public SSH key into the textarea and click the "Upload SSH public key" button to save
  6. Create a stack based on the showcase.json template
  7. Wait until the stack status is CREATE_COMPLETE
  8. Copy the PublicName from the stack's outputs
  9. Connect via ssh ssh $Username@$PublicName replace $Username with your IAM user and $PublicName with the stack's output

How to integrate this system into your environment (non-CloudFormation)

  1. Upload your public SSH key to IAM as above
  2. Make sure any instances you want to ssh into contain the correct IAM permissions (usually based on IAM Profile, but also possibly based on an IAM user and their credentials). Look at the iam_ssh_policy.json for an example policy that will permit login.
  3. Make sure those instances automatically run a script similar to install.sh (note - that script assumes git is installed and instances have access to the Internet; feel free to modify it to instead install from a tarball or using any other mechanism such as Chef or Puppet).
  4. Connect to your instances now using ssh $Username@$PublicName with $Username being your IAM user, and $PublicName being your server's name or IP address.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.