ssh到ec2实例中。

ssh-aws的Python项目详细描述


awssh

awssh使用boto3列出aws实例,并基于 “密钥名”。它支持aws cli--profile--region选项以及环境变量 (aws_default_region、aws_default_profile等)指定配置选项和凭据。

➜  ~ awssh
Querying AWS for EC2 instances in default region...

     Name           Instance ID   Public IP       Private IP       Zone          Key Name
 0 - JumpHost-1     i-06755dff7   3.13.18.215     10.120.1.119     us-east-2a    project-100715
 1 - WinStack       i-088fbe001   None            10.120.1.40      us-east-2a    project-100715
 2 - JumpHost-2     i-00498e224   48.14.28.186    10.120.0.8       us-east-2a    project-101018
 3 - PCoIP          i-0b79c1a8f   None            10.120.1.46      us-east-2a    project-101018
 4 - Dyna-dyna      i-03ed2e9df   None            10.120.1.7       us-east-2a    project-101018
 5 - ECS Instance   i-01b2877c1   None            10.120.1.55      us-east-2a    project-101018
 6 - MySQL-PROD     i-01b2877c1   None            10.120.1.55      us-east-2a    project-100715
 7 - codeCommit     i-06755dff7   None            10.120.1.119     us-east-2a    project-100715

Enter server number: 7

Connecting to codeCommit via JumpHost-1:

[centos@code-commit ~]$

安装

首先,安装aws cli和boto3库:

pip3 install awscli --upgrade --user
pip3 install boto3

接下来,设置aws凭据、默认配置文件和默认区域:

aws configure

注意:配置 AWS Profiles 才能使用--profile选项和aws_default_profile环境变量。

安装awssh实用程序:

pip3 install ssh-aws --user  # or pip3 install ssh-aws

最后,根据您的python版本,确保$HOME/Library/Python/<version>/bin是path的一部分。

echo$PATH

noteawssh实用程序安装在$HOME/Library/Python/<version>/bin中,可能不在您的路径上。

版本更新

echo y | pip3 uninstall ssh-aws
pip3 install ssh-aws --no-cache --user  # or pip3 install --no-cache ssh-aws
awssh --version

要求

功能

awssh实用程序为您提供了一个aws实例列表和带有正确键和用户的预配置。 可以按实例名称筛选。如果它只匹配一个实例,您将登录到它。如果一个实例 如果未选择外部IP,该实用程序将尝试查找其跳转服务器和带有ProxyJump的ssh 配置指令(例如ssh -A -J user@<jump.host> user@<target.host>)。代理转发应该是 小心使用。awssh还允许本地和远程端口转发用于ssh隧道 (例如ssh -L 9000:imgur.com:80 user@<ip_address>)。

用法

usage: awssh [-h] [--users USERS [USERS ...]] [--profile PROFILE]
             [--region REGION] [-i KEY_PATH] [-c COMMAND]
             [-r REMOTE_HOST] [-p REMOTE_PORT] [-l LOCAL_PORT]
             [--keys KEYS] [--timeout TIMEOUT] [--console-output]
             [--version] [--verbose]
             [filter]

SSH into AWS instances. "awssh --profile prod-acc-2 --users fduran --region
us-east-2 instance-name". The default user list is centos, ubuntu, and
ec2-user. "awssh --profile prod-acc-2" will attempt ssh with default users.
Due to the nature of nargs, "awssh --users user1 user2 instance-name" will not
be parsed properly; instead try "awssh instance-name --users user1 user2". If
available, a "JumpHost" will be automatically chosen when the instance
selected has no external IP. You can also explicitly direct the JumpHost by
providing two selections from the list, i.e. Enter server number: <jump>
<target>).

positional arguments:
  filter                Optional instance name or key word as a filter. If
                        only one instance is found, it will connect to it
                        directly.

optional arguments:
  -h, --help            show this help message and exit
  --users USERS [USERS ...]
                        Users to try (centos, ubuntu, and ec2-user are
                        defaults).
  --profile PROFILE     Use a specific profile from your credentials file.
  --region REGION       AWS region (User default if none is provided).
  -i KEY_PATH, --key-path KEY_PATH
                        Specific key path, overrides, --keys
  -c COMMAND, --command COMMAND
                        Translates to ssh -t <COMMAND>
  -r REMOTE_HOST, --remote-host REMOTE_HOST
                        Open a tunnel. Equivalent to ssh -L <local-port
                        >:<remote-host>:<remote-port> <selected-aws-host>
  -p REMOTE_PORT, --remote-port REMOTE_PORT
                        Port to use on the remote host (default is 5432).
  -l LOCAL_PORT, --local-port LOCAL_PORT
                        Port to use on the local host. Get overwritten by
                        remote port if not defined.
  --keys KEYS           Directory of the private keys (~/.ssh by default).
  --timeout TIMEOUT     SSH connection timeout.
  --console-output, -o  Display the instance console out before logging in.
  --version, -v         Returns awssh's version.
  --verbose, -V         Verbose, prints instance details.


  Examples:
    awssh
    awssh --profile prod-acc-2
    awssh --users fduran --profile prod-acc-2 --region us-east-2 -c top
    awssh --users user1 user2 --region us-east-2 --keys '~/.ssh' instance-name
    awssh --users user1 user2 -c 'df -h' --verbose

pypi.org

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Libgdx手势监听器不适用于手机,但适用于桌面   json使用Java从MongoDB返回多个文档   Apache VFS的java SSH URI错误   java JPA createNativeQuery getResultList<Object[]>跳过空字段   java如何在没有ImageIO的情况下将加载的字节转换为图像。读()   类如何获取“导入java”。净。*'工作?   虽然引发了异常,但java事务未回滚   java正在从应用程序获取敏感数据。形态   java在当前线程结束后启动线程   分类如何在java代码中结合weka和LibSVM   java如何压缩图像直到达到固定字节大小   java与extras之间存在一些问题   带过滤器链接的java并行流   java生成ID高于某个值   IF语句可以在数学中使用吗。麦克斯在爪哇?   java JdbcTemplate如何在从数据库中删除表的情况下检索数据   如何在java中更新excel文件?   java无法运行JApplet,因为安全问题无法加载库   hh:mm格式的java时间条目   找不到java变量,即使它在上面的类中