awssh

package module
v0.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

awssh

Go Report Card

CLI tool to login ec2 instance.

  • You can close the ssh port in the security group.
  • It is not necessary to register the ssh public key.
  • You don't need to know public ip of ec2 instance.

Architecture

architecture

Install

  • Brew
$ brew tap youyo/tap
$ brew install awssh

Other platforms are download from github release page.

Requirements

IAM Policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2-instance-connect:SendSSHPublicKey",
                "ssm:StartSession",
                "ec2:DescribeSubnets",
                "ec2:DescribeInstances",
                "ec2:DescribeTags",
                "ec2:CreateImage",
                "ec2:CreateTags"
            ],
            "Resource": "*"
        }
    ]
}

Usage

$ awssh

demo

$ awssh --help
CLI tool to login ec2 instance.

Usage:
  awssh [instance-id] [flags]

Flags:
      --cache                     enable cache a credentials.
      --duration string           cache duration. (default "1 hour")
  -c, --external-command string   feature use.
  -h, --help                      help for awssh
  -i, --identity-file string      identity file path. (default "~/.ssh/id_rsa")
  -p, --port string               ssh login port. (default "22")
      --profile string            use a specific profile from your credential file. (default "default")
  -P, --publickey string          public key file path. (default "identity-file+'.pub'")
      --select-profile            select a specific profile from your credential file.
  -u, --username string           ssh login username. (default "ec2-user")
      --version                   version for awssh

Examples

Login to instance
$ awssh
Login to specific instance
$ awssh i-instanceid0000
Custom username and ssh port
$ awssh i-instanceid0000 --username admin --port 20022
Specific identity-file and publickey
$ awssh --identity-file '~/.ssh/custom.pem' --publickey '~/.ssh/custom.pem.pub'
Use specific aws profile
$ awssh --profile profile-1

or

$ export AWS_PROFILE=profile-1
$ awssh
Select aws profile
$ awssh --select-profile
Enable cache a credentials

If you use mfa authentication, it may be difficult to authenticate each time.
--cache option caches credentials and reuses it next time. Cache file is create to ~/.config/awssh/cache/* .
--duration options is modify a cache ttl. It is affected by the maximum session duration of the IAM role. Use the AssumeRole API. See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html#id_roles_use_view-role-max-session .

$ awssh --cache --duration "2 hours"
Assume Role MFA token code: 000000

demo-cache

Author

youyo

Documentation

Index

Constants

View Source
const (
	CmdSessionManagerPlugin      string = "session-manager-plugin"
	CmdSessionManagerPluginOrder string = "StartSession"
	CmdSsh                       string = "ssh"
)
View Source
const (
	CachePath string = "~/.config/awssh/cache"
)
View Source
const (
	ConnectHost string = "127.0.0.1"
)
View Source
const (
	DocumentNameAwsStartPortForwardingSession string = "AWS-StartPortForwardingSession"
)

Variables

This section is empty.

Functions

func ExecSshLogin

func ExecSshLogin(username, host, port, identityFilePath string) (err error)

func PreRun

func PreRun(cmd *cobra.Command, args []string) (err error)

func Run

func Run(cmd *cobra.Command, args []string) (err error)

func Validate

func Validate(cmd *cobra.Command, args []string) (err error)

Types

type Cache

type Cache struct {
	Store   *filesystem.FSStore
	Marshal *onecache.CacheSerializer
	Key     string
}

func NewCache

func NewCache(path, key string) (c *Cache, err error)

func (*Cache) Load

func (c *Cache) Load() (creds *credentials.Value, err error)

func (*Cache) Save

func (c *Cache) Save(creds *credentials.Value, expire time.Duration) (err error)

type Instance

type Instance struct {
	ID      string
	TagName string
}

type Instances

type Instances []Instance

type SsmDocument

type SsmDocument struct {
	Target       string                `json:"Target"`
	DocumentName string                `json:"DocumentName"`
	Parameters   SsmDocumentParameters `json:"Parameters"`
}

type SsmDocumentParameters

type SsmDocumentParameters struct {
	PortNumber      []string `json:"portNumber"`
	LocalPortNumber []string `json:"localPortNumber"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址