Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell script for configuring SSH via SSM #130

Merged
merged 3 commits into from
Aug 29, 2022

Conversation

BrunoGrandePhD
Copy link
Contributor

@BrunoGrandePhD BrunoGrandePhD commented Aug 24, 2022

I often find myself having to remotely access EC2 instances using SSM. I typically want to use SSH because I either want to copy files off of the EC2 instance using SCP or edit files using VS Code (with the SSH Remote extension). This requires me running through the same steps every time. In light of this, I decided to capture those commands in a shell script that can automate the setup and minimize mistakes.

Here's an example command and associated output:

bash setup-ssh-via-ssm.sh i-0421aea79957b510c

Running the following shell script on i-0421aea79957b510c...
  cd
  mkdir -p .ssh;
  echo [...] > .ssh/authorized_keys;
  sudo cp -r .ssh /home/ec2-user/;
  sudo chmod 700 /home/ec2-user/.ssh;
  sudo chmod 600 /home/ec2-user/.ssh/authorized_keys;
  sudo chown -R ec2-user:ec2-user /home/ec2-user/.ssh;

Starting session with SessionId: bruno.grande@sagebase.org-0d714049d8619edac


Exiting session with sessionId: bruno.grande@sagebase.org-0d714049d8619edac.


You should now be able to connect using 'ssh i-0421aea79957b510c'.
You can just use the SSH command for this instance going forward.
Connecting now...

Last login: Wed Aug 24 19:55:28 2022 from localhost

   __|  __|  __|
   _|  (   \__ \   Amazon Linux 2 (ECS Optimized)
 ____|\___|____/

For documentation, visit http://aws.amazon.com/documentation/ecs
17 package(s) needed for security, out of 43 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-172-22-0-82 ~]$ 

@BrunoGrandePhD BrunoGrandePhD marked this pull request as ready for review August 24, 2022 19:58
@BrunoGrandePhD BrunoGrandePhD requested a review from a team as a code owner August 24, 2022 19:58
bin/setup-ssh-via-ssm.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@tthyer tthyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BrunoGrandePhD BrunoGrandePhD merged commit 4ae17cf into main Aug 29, 2022
@BrunoGrandePhD BrunoGrandePhD deleted the bgrande/setup-ssh-via-ssm branch August 29, 2022 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants