June 2019: Check out Amazon EC2 Instance Connect as a replacement for this project
September 2018: Check out AWS Systems Manager Session Manager as a replacement for this project
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 addingone 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 usersto this group as they will be deleted in the next sync. This group is used by aws-ec2-ssh to keep trackof 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步骤1:启动Amazon EC2实例 视频演示:启动AWS EC2实例 导航到Amazon EC2并开始启动新实例。在本教程中,我将使用Amazon Linux 2 AMI(HVM)操作系统。 创建一个没有规则的新安全组(例如MediumSG)并分配给您的EC2实例: 步骤2:创建AWS IAM职能 视频演示:创建AWS IAM职能 导航到AWS IAM并创建新职能。选择EC2服务,然后单击Nex
如果EC2实例忘记了密码或秘钥,该如何重置密码和秘钥呢? 方法1:输入用户信息 警告:在开始执行此过程之前,请注意以下事项: 此过程需要停止和启动您的 EC2 实例。请注意,实例存储卷中的数据将丢失。有关更多信息,请参阅确定实例的根设备类型。请务必备份您想保存在实例存储卷上的所有数据。 停止并重新启动实例会更改实例的公有 IP 地址。在将外部流量路由到您的实例时,最佳做法是使用弹性 IP 地址而不
在界面创建好ec2,选择aws linux, 并创建了pairKey。 回到自己的终端,输入: ssh -i ~/Downloads/udemy22Test.pem ec2-user@ec2-34-221-234-36.us-west-2.compute.amazonaws.com 因为pairKey udemy22Test.pem 位于Download文件夹下,所以需要这个路径。 但是爆警
问题描述: 亚马逊云服务器ubuntu 16.04开启之后默认用户名为ubuntu 但是只能使用创建服务器时生成的pem密钥文件登陆,部分 运维人员不太习惯这种登录方式,按照下面的操作可以调整 为使用密码登录的方式。 反向操作请参考另一篇文章 https://blog.csdn.net/donghaiming111/article/details/80854223 创建新用户 sudo addus
如果你最近发现在密钥和网络配置均未改动的情况下,无法通过SSH登录新建的EC2实例,那么大概率是因为AWS新升级的Linux系统:Amazon Linux 2023 引起的。某些SSH客户端不会给出具体的错误信息,而某些客户端会给出这样的错误提示: Couldn't agree a host key algorithm (available: ecdsa-sha2-nistp256,ssh-ed2
AWS EC2 Linux | ssh 使用密码登录 1、使用AWS控制台创建的密钥对或者直接通过网页登录 注意:使用pem私钥不允许直接登录root用户,只能登录默认用户例如:ec2-user ,ubuntu等等 2、创建root密码 sudo passwd root 3、切换到root用户 su root 4、修改 sshd_config 文件 vim /etc/ssh/sshd_conf
在AWS EC2 上安装JDK 1.Windows上用PowerShell远程登录EC2 //下载EC2XXX.pem密钥到桌面,x.x.x.x为EC2公网ip PS C:\Users\XX\Desktop> ssh -i EC2XXX.pem ec2-user@x.x.x.x Last login: Fri Dec 2 00:43:32 2022 from softbank1261212230
aws为了安全,也下了不少的功夫。比如说我们用ec2没有办法直接用root登录等等。 接下来,我来叫大家直接用密码登录系统 我们首先要重置root密码,输入命令 sudo passwd root 接着会输入两次新的root密码。 接下来切换到root帐号 su 接着输入刚才设定的root密码 我们还要重置centos的密码 passwd centos 还是重复重置root密码的那个过程。 能完这些
Amazon EC2,也被称为Amazon Elastic Compute Cloud,用于在Amazon Web Service(AWS)云中提供大小可调的计算容量。 利用Amazon EC2,不需要在前期投资计算硬件,不但节省资金,还能更快的开发和部署应用程序。 高可靠,高弹性的规模级云计算。 具有完全管理权限的虚拟机 提供附带许可和自带许可(BYOL)选项 AWS上的SQL —SQL on
问题 最新需要在AWS云上面的EC2上面部署Spring。 步骤 分配用户 sudo useradd --system --home /var/api --shell /sbin/nologin --comment "api user" --user-group api 创建文件夹 sudo mkdir /var/api && sudo chown -R api /var/api && sudo
aws学习开始了 最近遇到的一个问题是,创建的EC2无法连接。 原因找到了,因为自己创建的安全组入境规则没有选取SSH协议。对策是,修改安全组,选择SSH协议即可。
我对Apache真的不太了解,我按照一些教程安装了LAMP堆栈。我可以成功地ftp到/home/ec2用户并在那里上载文件,但我希望能够将文件上载到/var/www/html,或者在某个地方使用我的帐户将文件上载到web。 对不起,如果我的问题不是很有帮助,但我没有受过足够的服务器教育,无法提供更多信息。问我问题,我会尽力的。
AWS EC2 Instance Terraform module Terraform module which creates an EC2 instance on AWS. Usage Single EC2 Instance module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version
我正在测试在服务器上设置一个Git(EC2-Linux,Amazon)。一切都很好,但我做了一件事,我不能复制,我想理解。 我正在遵循以下Git在服务器https://git-scm.com/book/en/v2/git-on-the-server-setting-up-the-server上的教程 我创建了4个用户进行测试,并在服务器上创建了他们的ssh密钥。(User Git)在/home/G
如果从localhost连接,则一切正常,如果从ec2 aws连接-错误“[错误:未找到有效的replicaset实例服务器]” localhost和ec2 ubuntu上的代码是相同的 mongoose.connect('mongodb://:@cluster0-shard-00-00-llnwa.mongodb.net:27017cluster0-shard-00-01-llnwa.mongo
我已经在tomcat服务器上创建了我的java web应用程序,它将使用AWS java SDK启动另一个实例,在windows上,我只需将凭据放在我的用户中。我现在试图在AWS EC2实例上托管我的应用程序,因此我试图将我的凭据放在Linux EC2上。我已经在AWS SDK上执行了一些步骤-http://docs.aws.amazon.com/AWSSdkDocsJava/latest/Dev